Jump to content

image verification not working?


digitalLotus

Recommended Posts

Alright, I've posted this before in the "PHP Help" forum, however this post probably belongs better here.

I've been searching for an image verification script i can use for my registration form and found this one ( added below ). The only problem I somehow have is the fact that no matter what code I enter, it's accepted as correct and I receive the response "You are verified".

I might as well also point out that I'm quite new on the PHP platform.

 

verification.php:

 <?php
Header("Content-Type: image/png");

session_start();

$new_string;

session_register('new_string');

echo "<html><head><title>Verification</title></head>";
echo "<body>";

$im = ImageCreate(200, 40);

$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);

srand((double)microtime()*1000000);

$string = md5(rand(0,9999));

$new_string = substr($string, 17, 5);


ImageFill($im, 0, 0, $black);

ImageString($im, 4, 96, 19, $new_string, $white);

ImagePNG($im, "verify.png");
ImageDestroy($im);

echo "<img src=\"verify.png\">";
echo "<br><br>";
echo "Type the code you see in the image in the box below. (case sensitive)";
echo " <form action=\"formhandler.php\" method=post>";
echo "<input name=\"random\" type=\"text\" value=\"\">";
echo "<input type=\"submit\">";
echo "</form>";
echo "</body>";
echo "</html>";
?>

 

formhandler.php:

 <?php

session_start();

$random = trim($random);

if ($new_string == $random){
echo "You are verified";
}
else{
echo "Please go back and get verified.";
}
?>

 

Thanks in advance for any help.

Cheers.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.