Jump to content

capcha image problem


next

Recommended Posts

I just found a tutorial on capcha and can't figure out how to get it to work:

form.php

<?php
session_start();
if(isset($_POST['submit'])) {
$secCode = isset($_POST["secCode"]) ? strtolower($_POST["secCode"]): "";
if($secCode == $_SESSION["securityCode"]) {
	echo "<p>The result code was valid!</p>";
	unset($_SESSION["securityCode"]);
	$result = true;
}
else {
	echo "<p>Invalid code, try again.</p>";
	$result = false;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
   <head>
      <title><?php echo $site_name; ?></title>
      <style type="text/css">img {margin: 0 10px;}</style>
      <script type="text/javascript" src="javascript.js"></script>
   </head>
   <body>
<form action="<?php $PHP_SELF ;?>" method="post">
	<label for="securityCode">Security Code
		<input type="text" name="securityCode" size="10" /><img src="securityCode.php" alt="security" border="1"></label>

	<input type="submit" name="submit" value="submit" />			
</form>
   </body>
</html>

 

securityCode.php

<?php
$width = 120;
$height = 40;
$baseList = '0123456789abcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

//generate image
$image = @imagecreate($width, $height) or die("Unable to initialize GD.");
for($i = 0; $i < 10; $i++) {
	imageline($image,
				mt_rand(0, $width), mt_rand(0, $height),
				mt_rand(0, $width), mt_rand(0, $height),
				imagecolorallocate($image, mt_rand(150, 255), mt_rand(150, 255), mt_rand(150, 255)));
}
//add random characters to image
for($i = 0, $x = 0; $i < $length; $i++) {
	$actChar = substr($baseList, mt_rand(0, strlen($baseList)-1), 1);
	$x += 10 + mt_rand(0, 10);
	imagechar($image, mt_rand(3, 5), $x, mt_rand(5, 20), $actChar,
				imagecolorallocate($image, mt_rand(0, 155), mt_rand(0, 155), mt_rand(0, 155)));
	$code .= strtolower($actChar);
}

header("Content-Type: image/jpeg");
imagejped($image);
imagedestroy($image);

$_SESSION["securityCode"] = $code;
?>

 

My problem is that it never shows the actual image, i see only alternative text(img alt="security"). I though that maybe my GD is disabled but here's what my phpinfo() shows:

GD Support enabled

GD Version bundled (2.0.34 compatible)

FreeType Support enabled

FreeType Linkage with freetype

FreeType Version 2.1.9

T1Lib Support enabled

GIF Read Support enabled

GIF Create Support enabled

JPG Support enabled

PNG Support enabled

WBMP Support enabled

XBM Support enabled

 

How do i get it to work?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/107513-capcha-image-problem/
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.