This is the verification code i put in my webpage

<?php if ($use_verification_image): ?>
	<label for="commentform_verification">Image verification:</label><br />
	<input name="verification" type="text" id="commentform_verification" class="comment_form_text_box"/>
	<br />
	<img src="<?php echo $commentsystemfolder; ?>comments_verificationimage.php?r=<?php echo md5(uniqid(time())); ?>" alt="image verification" name="commentform_verificationimage" width="70" height="10" id="commentform_verificationimage"/><br /><br />
	<?php endif; ?>


the above code is coming from this verification file:

<?php

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

$randomstring = substr(md5(uniqid(time())),0,6);
$width = 100;
$height = 20;
$canvas = imagecreatetruecolor($width, $height);

setcookie('tntcommentvf', md5(md5($randomstring) . 'a39nx'), null, '/');

imageantialias($canvas, true);
imagefill($canvas, 0, 0, 0xFFFFFF);

for ($i = 0; $i < 100; $i++){
	$x = rand(0,$width-1);
	$y = rand(0,$height-1);
	imagesetpixel($canvas, $x, $y, 0x000000);
}

$x = 4;
for ($c = 0; $c < strlen($randomstring); $c++){
	$x += 8 + rand(0,5);
	$y = $height/2 - rand(0,2) + rand(0,2) - 8;
	imagestring($canvas, 3, $x, $y, substr($randomstring,$c,1), 0x000000);
}

imagejpeg($canvas);
imagedestroy($canvas);


?>

But somehow the image is not showing up.

Recommended Answers

All 2 Replies

hi,
here is the code of captcha i used

if($_SERVER['REQUEST_METHOD']=="POST"){ 
 
if( $_SESSION['number'] == $_POST['number'] && !empty($_SESSION['number']) ) {
//insert into database operation
}
else{
$msg="";
$msg="sorry, the code u entered does not match try again";
}
//html, body,.....the table you use
<tr>
                    <td align="right">&nbsp;</td>
                    <td align="right" nowrap>please enter string shown </td>
                    <td align="center">&nbsp;</td>
                    <td width="31%"><input id="number" name="number" type="text" /></td>
                    <td width="13%"><img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><?php if(isset($msg)) { echo $msg;} ?></td>
                  </tr>

and in captchssecuritypage

<?php
session_start();
class CaptchaSecurityImages {

	var $font = 'monofont.ttf';

	function generateCode($characters) {
		/* list all possible characters, similar looking characters and vowels have been removed */
		$possible = '23456789bcdfghjkmnpqrstvwxyz';
		$code = '';
		$i = 0;
		while ($i < $characters) { 
			$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
			$i++;
		}
		return $code;
	}

	function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
		$code = $this->generateCode($characters);
		/* font size will be 75% of the image height */
		$font_size = $height * 0.75;
		$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
		/* set the colours */
		$background_color = imagecolorallocate($image, 255, 255, 255);
		$text_color = imagecolorallocate($image, 20, 40, 100);
		$noise_color = imagecolorallocate($image, 100, 120, 180);
		/* generate random dots in background */
		for( $i=0; $i<($width*$height)/3; $i++ ) {
			imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
		}
		/* generate random lines in background */
		for( $i=0; $i<($width*$height)/150; $i++ ) {
			imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
		}
		/* create textbox and add text */
		$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
		$x = ($width - $textbox[4])/2;
		$y = ($height - $textbox[5])/2;
		imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
		/* output captcha image to browser */
		header('Content-Type: image/jpeg');
		imagejpeg($image);
		imagedestroy($image);
		$_SESSION['number'] = $code;
	}

}

$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';

$captcha = new CaptchaSecurityImages($width,$height,$characters);

?>

i got this code from a site and i modified according to my requirement
i forgot that site so, i am giving u my code
hope this will help u

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.