Image Verification

B

Brandon

Guest
Image Verification

I'm sure all of you have gone to an email and when your logging in you get a message saying to verify the words in the box.

This is for security so people can not make "bots" automatily sign-up for a service or send massive amounts of emails.

You need PHP and the GD Library. (X10 has this installed)

Create a php file and name it verification.php inside post this code.

<FONT style="BACKGROUND-COLOR: #ffffff">
PHP:
<?php
session_start();
$random = trim($random);
if ($new_string == $random){
ON THIS LINE YOU MAY PLACE ANYTHING YOU WANT TO HAPPEN AFTER VERIFICATION 
}
else{
echo "Please go back and type the code exactly as shown.";
}
?>
Then create another file this time named form.php inside post this code.

<FONT style="BACKGROUND-COLOR: #ffffff">
PHP:
<?php
Header("Content-Type: image/png");
session_start();
$new_string;
session_register('new_string');
echo "<html><head><title>Verification Check</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>";
?>
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
One suggestion, it really won't matter until PHP 6 is released (I believe it will be taken out then.. Maybe someone else could clarify this for me?)

Your using session_register() to create and register session variables. That method is depreciated, so I would just recommend you (And others.. ) to use the $_SESSION super globe array and just edit/alert/delete variables from there like:
PHP:
$_SESSION['var_name'] = value;
Instead of:
PHP:
session_register('var_name');
$var_name = value;

Eh, just a suggestion.

By the way, good tutorial. I'm sure many people will find a good use for this. :)
 

Jordan K

[B]tags dont work:([/B]
Messages
1,528
Reaction score
0
Points
0
NedreN said:
One suggestion, it really won't matter until PHP 6 is released (I believe it will be taken out then.. Maybe someone else could clarify this for me?)

Your using session_register() to create and register session variables. That method is depreciated, so I would just recommend you (And others.. ) to use the $_SESSION super globe array and just edit/alert/delete variables from there like:
PHP:
$_SESSION['var_name'] = value;
Instead of:
PHP:
session_register('var_name');
$var_name = value;

Eh, just a suggestion.

By the way, good tutorial. I'm sure many people will find a good use for this. :)

Someone studies his PHP daily. :) Great tip to everyone that's using this, I might in the future after I completely change my website around.:drool:
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
Haha, it's been 2 long years to get where I am. I still don't know all that much..

And your welcome DesertWar
 
Top