i found the following code in a website. i am trying to use it. but the captcha image is not displaying in any browser.
the following is the code i am trying.
<?php
// Start the session
session_start();
// Generate randomness from MD5
$rand = mt_rand();
//echo $rand."<br>";
// String for randomness
$string = substr($rand, 0, 10);
//echo $string;
// Set the session
$_SESSION['captcha'] = $string;
/*
@ NOW WE CAN MAKE THE IMAGE!!
*/
$img = imagecreatefrompng("captcha.png");
// Colours
$linecolour = imagecolorallocate($img, 250, 250, 250);
$textcolour = imagecolorallocate($img, 0, 0, 0);
// Other variables
$lines = 10;
$i = 1; # Don't change
$xcentre = (150 / 2) - ((strlen($string) / 2) * imagefontwidth(5)); # Centre the text X
$ycentre = (25 - imagefontheight(5)) / 2; # Centre the text Y
// Repeat the lines
while($i <= $lines){
$randxs = rand(0, 150); # Random X start point
$randys = rand(0, 0); # Random Y start point
$randxe = rand(0, 150); # Random X end point
$randye = rand(0, 50); # Random Y end point
imageline($img, $randxs, $randys, $randxe, $randye, $linecolour);
$i += 1;
}
// Echo text
imagestring($img, 5, $xcentre, $ycentre, $string, $textcolour);
// Send headers (save time laters)
header("Content-Type: image/png");
imagepng($img); # Echo image out
imagedestroy($img); # Destroy image
?>
the image captcha.png was in the current working directory.
but i am getting the following error in mozilla
The image “http://localhost/temp/test.php” cannot be displayed, because it contains errors.
i don't know what is causing this error. in other browsers no error msg is being displayed. but they are showing broken image link symbol
can anyone help me pls.. i got this code from x10hosting.com forums site.
This post has been edited by kummu4help: 02 December 2008 - 11:42 PM

New Topic/Question
Reply




MultiQuote




|