- Joined
- Apr 29, 2005
- Messages
- 6,400
- Reaction score
- 130
I'm totally lost on this one. As you can see here: cuteness.pie-designs.net/test2.php
The security image displays without any problem. However if you enter the right code, it still echoes "Oops the security code does not match the code shown in the image."
The scripts I'm using:
captcha.php
The image)
test2.php:
I've already checked if the code gets inserted properly in the db.
Any suggestions?
The security image displays without any problem. However if you enter the right code, it still echoes "Oops the security code does not match the code shown in the image."
The scripts I'm using:
captcha.php

PHP:
<?php
$width = 160;
$height = 40;
$characters = 5;
$font_size = 12;
$im = imagecreate($width, $height);
$bg = imagecolorallocate($im, 0, 0, 0);
$character_array = array("A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9");
$i = 0;
while ($i<5)
{
imageline($im, rand(0, 8), rand(0, $height), ($width-rand(0, 8)), rand(0, $height), imagecolorallocate($im, rand(95, 159), rand(95, 159), rand(95, 159)));
$i++;
}
$total_string = "";
$i=0;
while ($i<$characters)
{
$string = $character_array[rand(0, (count($character_array)-1))];
$total_string .= $string;
$textcolor = imagecolorallocate($im, rand(127, 255), rand(127, 255), rand(127, 255));
imagestring($im, 5, rand((((($width)/$characters)*$i)+3), ((($width/$characters)*($i+1))-16)), rand(0, ($height-20)), $string, $textcolor);
$i++;
}
mysql_connect('localhost', '***', '***');
mysql_select_db('***');
$insert = mysql_query("INSERT INTO verification VALUES ('', '".md5($total_string)."', '".$_SERVER['REMOTE_ADDR']."', '".time()."')") or exit('Error!');
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
test2.php:
PHP:
$connection = mysql_connect($host, $user, $pass) or die ("unable to connect");
mysql_select_db($db) or die ("Unable to select database!");
$_POST['code'] = strtoupper($_POST['code']);
if (empty($_POST['code']))
{
$error[] = 'You must fill in the <b>security code</b>.';
}
elseif (!ereg("^[A-Z]{5}$", $_POST['code']))
{
$error[] = 'the <b>security code</b> does not match the code shown in the image.';
}
else
{
$select = mysql_query("SELECT code FROM verification WHERE code = '".md5($_POST['code'])."'' LIMIT 1");
mysql_query("DELETE FROM verification WHERE ip_address = '".$_SERVER['REMOTE_ADDR']."' OR time <= '".(time()-(60*60))."'");
if (!mysql_num_rows($select))
{
$error[] = 'the <b>security code</b> does not match the code shown in the image.';
}
else { $code = true; }
}
if ($code == true)
{
echo 'code was allright';
}
else
{
echo 'Oops ';
foreach($error as $single_error)
{
echo $single_error.'<br>';
echo $_POST['code'];
}
}
}
?>
I've already checked if the code gets inserted properly in the db.
Any suggestions?