Re: Which CAPTCHA is the besta?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Here's a simple one you can hack to fit your needs.

This a file for generating the captcha image.
<?php
/**
 * Makes graphical image of supplied number argument
 */

	session_start();
	$num_str= $_SESSION['scode_show'];
	if(isset($_GET['scode'])) $num_str= $_GET['scode'];

	header ("Content-type: image/jpeg");

//	$width	= 60;									//Box size, adjust as required
//	$height	= 34;
//	$font= 'gogobig.gdf';							//pick one
	$font= 'addlg10.gdf';
//	$font= 'automatic.gdf';
//	$font= 5;										//default

	$font = imageloadfont($font);
	$height= imagefontheight($font) + 6;
	$width= imagefontwidth($font)*strlen($num_str)+6;

$src = @imagecreate($width, $height) or die("Cannot Initialize new GD image stream");
	$background_color = imagecolorallocate($src, 200, 200, 200);
	$text_color = imagecolorallocate($src, 20, 20, 255);

	imagestring($src, $font, 3, 3,  $num_str, $text_color);

	imagejpeg($src);
	imagedestroy($src);
?>

This is the code snippet for your client page:

/**
 * This is a typical use of the catcha code
 *
 *
 */
//**** Security Code ***********/

	$sid= session_id();							//See if session handler exists

if(empty($sid)) session_start(); //This also places a session cookie, if enabled by client's browser

$scode= rand(100, 999); //pick the range as you like. 100 to 999 is probably sufficent

	$_SESSION['scode'];

$prev_scode= $_SESSION['scode_show']; //This is the scode the user saw previously and was to enter $_SESSION['scode_show']= $scode; //Set an new scode; this is used by make_scode_img.php for the label graphic generation

	$scode_passed= (isset($_SESSION['scode_passed']))? TRUE:FALSE;
//print_r($_SESSION);
if(!$scode_passed && isset($_POST['scode']) && $_POST['scode']== $prev_scode) $scode_passed= TRUE; //If not set, see if passed

	$scode_txt= NULL;	//So can be used without a if() test

	if(!$scode_passed){

		$len= strlen($scode)+2;
		$scode_txt .= <<<txt
<form enctype="multipart/form-data" action="{$_SESSION['PHP_SELF']}" name="interview" method="post"> <p>To prevent SPAM, we need you to enter this security number in the box on the right and key Submit. <img style="margin-right:2em; border:blue 2px solid" src="make_scode_img.php" alt="missing img file"> <input style="margin-right:2em; font-size:10pt" type="text" maxlength= "$len" size="$len" name="scode", value="">
<input style="font-size:11pt" type="submit" name="scode_submit" value="Submit">
</p>
</form>
</body>
</html>
txt;
}
/**
* Note, put this code in the html where you want the log-in to be rendered. Notice, it has an exit; You don't need the if() you don't
 * need the exit.  $code_txt is NULL unless the $scode_passed is TRUE.
 * <?php
 * 	if(!$scode_passed) {
 * 	echo "<p>$scode_txt</p>\n\n";
 * 	exit;														//This ends the page
 * 	}
 * ?>
 */
	if($scode_passed){											

Tony Di Croce wrote:
I need a CAPTCHA script.... Which one is the best? (I dont mind if its
somewhat difficult).


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux