Welcome to Geeklog, Anonymous Monday, December 23 2024 @ 06:49 am EST
Geeklog Forums
Captcha integration
Status: offline
Robin
Forum User
Full Member
Registered: 02/15/02
Posts: 725
Hello
I've been wondering how difficult it would be to integrate captcha with e.g. a form used for sending so called suggestions by users?
I've successfully setup Captcha with GL 1.4.1 however spammers found their way via this "suggest" block.
Any help much appreciated
Robert
Geeklog Polish Support Team
I've been wondering how difficult it would be to integrate captcha with e.g. a form used for sending so called suggestions by users?
I've successfully setup Captcha with GL 1.4.1 however spammers found their way via this "suggest" block.
Any help much appreciated
Robert
Geeklog Polish Support Team
20
16
Quote
Status: offline
mevans
Forum User
Full Member
Registered: 02/08/04
Posts: 393
Location:Texas
Robert,
Integrating CAPTCHA should be pretty simple. Unfortunately, I'm working remotely right now and don't have access to my source code / tools so I can't give you a good example at the moment.
This evening when I get home I'll post a reply here with some sample code to get you going.
Thanks!
Mark
Integrating CAPTCHA should be pretty simple. Unfortunately, I'm working remotely right now and don't have access to my source code / tools so I can't give you a good example at the moment.
This evening when I get home I'll post a reply here with some sample code to get you going.
Thanks!
Mark
14
18
Quote
Status: offline
mevans
Forum User
Full Member
Registered: 02/08/04
Posts: 393
Location:Texas
Robert,
Here is a quick and dirty CAPTCHA integration code snip:
To include the CAPTCHA graphic in your suggestion page, you simply do the following:
// code to add the captcha prompt...
// $name - must be one of the following:
// - comment
// - story
// - registration
// - contact
// - emailstory
// - forum
$captcha = CAPTCHA_getHTML($name);
$template->set_var('captcha', $captcha);
The $name variable is used to determine which template to use for generating the HTML. I think I need to add a general one as well. For now, you can choose the template that comes closest to meeting your needs for the generated HTML. Look in the plugins/captcha/templates/ directory for the template files (captcha_comment.thtml, captcha_story.thtml, etc.).
Once you have the graphic on your form, in the code that processes the form add the following:
// code to check the entered captcha value
// - 'type' is the plugin/staticpage name, put whatever you want there
// - $str - this is the CAPTCHA string entered by the user
list( $rc, $msg ) = CAPTCHA_checkInput( 'type',$str );
if ( $rc == 1 )
return 0; // did not match
else
return 1; // it matched
The type parameter should probably be set to suggestion in your case. It is used to log any CAPTCHA entry failures, so you would see something like this in your Geeklog error.log
CAPTCHA: An invalid CAPTCHA string was entered in suggestion - IP Address: xxx.xxx.xxx.xxx
The $str variable is the CAPTCHA string entered by the user that you pull from the $_POST['captcha'] variable.
As you can see, integrating into your suggestion form should not be that tough. Let me know if you run into any issues or problems.
Thanks!
Mark
Here is a quick and dirty CAPTCHA integration code snip:
To include the CAPTCHA graphic in your suggestion page, you simply do the following:
Text Formatted Code
// code to add the captcha prompt...
// $name - must be one of the following:
// - comment
// - story
// - registration
// - contact
// - emailstory
// - forum
$captcha = CAPTCHA_getHTML($name);
$template->set_var('captcha', $captcha);
The $name variable is used to determine which template to use for generating the HTML. I think I need to add a general one as well. For now, you can choose the template that comes closest to meeting your needs for the generated HTML. Look in the plugins/captcha/templates/ directory for the template files (captcha_comment.thtml, captcha_story.thtml, etc.).
Once you have the graphic on your form, in the code that processes the form add the following:
Text Formatted Code
// code to check the entered captcha value
// - 'type' is the plugin/staticpage name, put whatever you want there
// - $str - this is the CAPTCHA string entered by the user
list( $rc, $msg ) = CAPTCHA_checkInput( 'type',$str );
if ( $rc == 1 )
return 0; // did not match
else
return 1; // it matched
The type parameter should probably be set to suggestion in your case. It is used to log any CAPTCHA entry failures, so you would see something like this in your Geeklog error.log
CAPTCHA: An invalid CAPTCHA string was entered in suggestion - IP Address: xxx.xxx.xxx.xxx
The $str variable is the CAPTCHA string entered by the user that you pull from the $_POST['captcha'] variable.
As you can see, integrating into your suggestion form should not be that tough. Let me know if you run into any issues or problems.
Thanks!
Mark
14
19
Quote
Status: offline
Robin
Forum User
Full Member
Registered: 02/15/02
Posts: 725
Mark thank you very much for your help :shakehands:
Unfortunately I didn't manage to implement it
Please take a look at this code. It displays the form.
This is an old suggest block by Mr.GxBlock.
global $_TABLES, $_CONF, $_USER;
$message="what would you like to see on the site?";
$siteurl = $_CONF['site_url'];
if($_USER['username'] != ''){
// we only need the email cos we know the username. They have already passed validation and therefore
// this cannot be spoofed. So, only select email from the database.
$result = DB_query("SELECT email FROM {$_TABLES['users']} WHERE username = '{$_USER['username']}'");
$U = DB_fetchArray($result);
$username = $_USER['username'];
$useremail = $U[email];
if($useremail == ''){
$useremail = 'anonymous@anonymous.com';
}
}elseif($_USER['username'] == ''){
$username = 'Guest';
$useremail = 'anonymous@anonymous.com';
}
$display ="<CENTER>";
$display .="<B>Hello $username, $message<B><BR>";
$display .="<FORM ACTION=\"$siteurl/suggest.php\" METHOD=\"POST\">";
$display .="<TEXTAREA ROWS=\"3\" COLS=\"15\" NAME=\"suggest\"></TEXTAREA><BR>";
$display .= "<INPUT TYPE=\"hidden\" NAME=\"username\" VALUE=\"$username\">";
$display .= "<INPUT TYPE=\"hidden\" NAME=\"useremail\" VALUE=\"$useremail\">";
$display .= "<INPUT TYPE=\"submit\" NAME=\"\" VALUE=\"Send!\">";
$display .= "</FORM>";
$display .="</CENTER>";
return $display;
}
Thank you
Robert
Geeklog Polish Support Team
Unfortunately I didn't manage to implement it
Please take a look at this code. It displays the form.
This is an old suggest block by Mr.GxBlock.
Text Formatted Code
function phpblock_suggest(){global $_TABLES, $_CONF, $_USER;
$message="what would you like to see on the site?";
$siteurl = $_CONF['site_url'];
if($_USER['username'] != ''){
// we only need the email cos we know the username. They have already passed validation and therefore
// this cannot be spoofed. So, only select email from the database.
$result = DB_query("SELECT email FROM {$_TABLES['users']} WHERE username = '{$_USER['username']}'");
$U = DB_fetchArray($result);
$username = $_USER['username'];
$useremail = $U[email];
if($useremail == ''){
$useremail = 'anonymous@anonymous.com';
}
}elseif($_USER['username'] == ''){
$username = 'Guest';
$useremail = 'anonymous@anonymous.com';
}
$display ="<CENTER>";
$display .="<B>Hello $username, $message<B><BR>";
$display .="<FORM ACTION=\"$siteurl/suggest.php\" METHOD=\"POST\">";
$display .="<TEXTAREA ROWS=\"3\" COLS=\"15\" NAME=\"suggest\"></TEXTAREA><BR>";
$display .= "<INPUT TYPE=\"hidden\" NAME=\"username\" VALUE=\"$username\">";
$display .= "<INPUT TYPE=\"hidden\" NAME=\"useremail\" VALUE=\"$useremail\">";
$display .= "<INPUT TYPE=\"submit\" NAME=\"\" VALUE=\"Send!\">";
$display .= "</FORM>";
$display .="</CENTER>";
return $display;
}
Thank you
Robert
Geeklog Polish Support Team
16
22
Quote
All times are EST. The time is now 06:49 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content