Jump to content

Captcha help.


Imad

Recommended Posts

Hi Guys, I need help with CAPTCHA. I created the captcha as shown below:

 

<?php
session_start();

$encrypt = md5(mktime() / time(myds) * microtime());
$string = substr($encrypt,0,;


$cap= imagecreatefrompng("cap.png");
$black = imagecolorallocate($cap, 0, 0, 0);
$grey = imagecolorallocate($cap, 105, 105, 105);
$four = imagecolorallocate($cap,233,239,239);

imageline($cap,0,0,39,29,$black);
imageline($cap,15,40,79,9,$four);
imageline($cap,18,34,70,3,$grey);
imageline($cap,23,39,76,9,$grey);
imageline($cap,80,30,50,0,$grey);
imageline($cap,90,50,70,0,$grey);
imageline($cap,90,50,93,0,$grey);


imagestring($cap, 10, 25, 15, $string, $black);
$_SESSION['key'] = md5($string);
header("Content-type: image/png");
imagepng($cap);
session_start();


?>

 

I then called it using this code:

 

<?php
session_start(cap.php); 
?>
<form method="post" name="captcha" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<img src="cap.php" />
<input type="text" name="test" />
<input type="submit" name="submit" value="check" />
</form>
<?php
if (isset($_POST['submit']) &&
($_SESSION['key'] =$_POST['test'])) {
echo 'sent';
}
elseif($_SESSION['key'] != $_POST['test']) {
		echo 'You entered the wrong code!';

	}
else {
echo 'nothing happened';
}
?>

 

I am a beginner with the CAPTCHA stuff so some help to get it working will be great. I know theirs something wrong with the sessions but I can't get it to work.

Best Regards.

Link to comment
https://forums.phpfreaks.com/topic/98369-captcha-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.