View Single Post
Old 02-22-2008, 01:30 AM   #12 (permalink)
qaiphyx
The Visitor
 
Join Date: Feb 2008
Posts: 2
Thanks: 0
qaiphyx is on a distinguished road
Default

Here's what I have.

Quote:
<?php
session_start();
//--------------------
// CAPTCHA Function
//--------------------
function captcha($length = 6) {
$length = isset($_GET['chars']) ? $_GET['chars'] : 6;

// Let's generate a totally random string using md5
$hash = md5(rand(0, 999));
// We don't need a 32 character long string so we trim it down to 5
$code = substr($hash, 15, $length);

// Set the session to store the security code
$_SESSION["captcha"] = $code;

// Set the image width and height
$width = 200;
$height = 50;

// Create the image resource
$image = imagecreate($width, $height);
// Random RGB colours
$rgb1 = rand(0, 255);
$rgb2 = rand(0, 255);
$rgb3 = rand(0, 255);

$background = imagecolorallocate($image, $rgb1, $rgb2, $rgb3);
$text = imagecolorallocate($image, ($rgb1 - 50), ($rgb2 - 50), ($rgb3 - 50));

// Make the background colour
imagefill($image, 0, 0, $background);

// Add randomly generated string in the image
for($i = 1; $i <= $length; $i++) {
$counter = rand(1, 2);

if ($counter == 1) {
$angle = rand(0, 45);
}
if ($counter == 2) {
$angle = rand(315, 360);
}

imagettftext($image, rand(14, 20), $angle, ($i * 25), 30, $text, "arial.ttf", substr($code, ($i - 1), 1));
}

// Add a border
imagerectangle($image, 0, 0, $width - 1, $height - 1, $text);

// Tell the browser what kind of file is come in
header("Content-Type: image/png");

// Output the newly created image in jpeg format
imagepng($image);

// Free up resources
imagedestroy($image);
}

!isset($_GET['chars']) ? captcha() : captcha($_GET['chars']);
?>
And for the image display page.

Quote:
<input type="text" name="captcha_confirm" />

<img src="captcha.php" />
theyre all in the same folder, and arial.ttf is in there too.

what am I doing wrong it doesnt show the img at the img src. its just white.
qaiphyx is offline  
Reply With Quote