However for normal applications or forums this might be working.
I tried to put notes into the script.
Basic GD support is required
index.php
Code: Select all
<?php
session_start();
$TempString=\"e;\"e;;
// Now we generate a string that consists of 6 characters that are
// generated randomly. I choose 6, because I didn´t want the user to
// type forever. Of course, any other number would do as well.
// (YOU USE ANOTHER NUMBER, YOU ALSO HAVE TO EDIT showimg.php)
for ($i = 1; $i <= 6; $i++) {
$TempString .= GetRandomChar();
}
//Now we create a Md5 string of that
$_SESSIONї'Rand_Text'] = $TempString;
$image_md5 = md5($TempString.\"e;secretpassphrase\"e;);
$imagerand = mt_rand(1,9999999);
function GetRandomChar() {
// This function generates our random chars
mt_srand((double)microtime()*1000000);
// Create a random number between 1 and 3
$RandVal = mt_rand(1,3);
// If the random number was 1, we generate a lowercase
// character, if it was 2, we generate a number and if
// it was 3, we generate an uppercase character.
switch ($RandVal) {
case 1:
// 97 to 122 are the ASCII codes for lower-case characters from a to z.
$RandVal = mt_rand(97, 122);
// exclude lowercase L and O
While ($RandVal == 108 || $RandVal == 111 ) {
$RandVal = mt_rand(97, 122);
}
break;
case 2:
// 48 to 57 are the ASCII codes for the numbers from 1 to 9.
$RandVal = mt_rand(49, 57);
break;
case 3:
// 65 to 90 are the ASCII codes for upper-case characters from a to z.
$RandVal = mt_rand(65, 90);
// exclude upperercase i and o
While ($RandVal == 73 || $RandVal == 79) {
$RandVal = mt_rand(65, 90);
}
break;
}
// Now we return the character, generated from the ASCII code
return chr($RandVal);
}
?>
<html>
<head>
<META HTTP-EQUIV=\"e;CACHE-CONTROL\"e; CONTENT=\"e;NO-CACHE\"e;>
<META HTTP-EQUIV=\"e;PRAGMA\"e; CONTENT=\"e;NO-CACHE\"e;>
<META HTTP-EQUIV=\"e;EXPIRES\"e; CONTENT=\"e;0\"e;>
</head>
<table width=\"e;500\"e; border=\"e;0\"e; cellspacing=\"e;0\"e; cellpadding=\"e;0\"e;>
<tr>
<td><hr size=\"e;1\"e; noshade=\"e;noshade\"e;>
<p><font size=\"e;2\"e; face=\"e;Verdana, Arial, Helvetica, sans-serif\"e;>Please type the code you see in the image into the textfield below. If you cannot read the code, just press \"e;<strong>Reload</strong>\"e; to generate a new one.</font></p>
<p align=\"e;center\"e;><font size=\"e;2\"e; face=\"e;Verdana, Arial, Helvetica, sans-serif\"e;><img src=\"e;showimg.php?<?php echo $imagerand.\"e;&\"e;.SID ?>\"e; width=150 height=40></font></p>
<form action=\"e;verify.php\"e; method=\"e;POST\"e; name=\"e;ImgVerify\"e;>
<p> <font size=\"e;2\"e; face=\"e;Verdana, Arial, Helvetica, sans-serif\"e;>Enter the code here: </font>
<input name=\"e;passcode\"e; type=\"e;text\"e; size=\"e;30\"e;maxlength=\"e;6\"e; value=\"e;\"e;></p>
<input type=\"e;hidden\"e; name=\"e;hash\"e; value=\"e;<?php echo $image_md5 ?>\"e;>
<p> <input type=\"e;submit\"e; name=\"e;Submit\"e; value=\"e;OK\"e; />
</p>
</form>
<p align=\"e;center\"e;><font size=\"e;2\"e; face=\"e;Verdana, Arial, Helvetica, sans-serif\"e;>
<B>Note:</b> The code you enter is case sensitive!
</p>
</td>
</tr>
</table>
</html>Code: Select all
<?php
session_start();
// Create the image with width=150 and height=40
$the_image = imagecreate(150,40);
// Allocate two colors (Black & White)
// This uses the RGB names of the colors
$color_back = imagecolorallocate ($the_image, 175,175,175);
$color_lineї1] = imagecolorallocate ($the_image, 137,137,137);
$color_frontї1] = imagecolorallocate ($the_image, 67,67,67);
$color_frontї2] = imagecolorallocate ($the_image, 77,77,77);
$color_frontї3] = imagecolorallocate ($the_image, 97,97,97);
$color_frontї4] = imagecolorallocate ($the_image, 87,87,87);
$color_frontї5] = imagecolorallocate ($the_image, 87,87,87);
// Flood Fill our image with backcolor
imagefill($the_image, 0, 0, $color_back);
//We get the random text that was stored in our session var on the first page.
$RandomText = $_SESSIONї\"e;Rand_Text\"e;];
$_SESSIONї\"e;Rand_Text\"e;] = \"e;\"e;;
// here we create a couple of random lines to distort the background
for ($i; $i < 8; $i++) {
ImageLine($the_image, mt_rand(0,25),mt_rand(0,40),mt_rand(125,150),mt_rand(0,40), $color_lineї1]);
}
// we now write the 6 random chars in our picture. Add a line if you chose another number in the initial page
mt_srand((double)microtime()*1000000);
imagechar($the_image, mt_rand(3,5), mt_rand(5,20), mt_rand(5,20), $RandomTextї0] ,$color_frontїmt_rand(1,5)]);
imagechar($the_image, mt_rand(3,5), mt_rand(30,40), mt_rand(5,20), $RandomTextї1] ,$color_frontїmt_rand(1,5)]);
imagechar($the_image, mt_rand(3,5), mt_rand(50,65), mt_rand(5,20), $RandomTextї2] ,$color_frontїmt_rand(1,5)]);
imagechar($the_image, mt_rand(3,5), mt_rand(75,90), mt_rand(5,20), $RandomTextї3] ,$color_frontїmt_rand(1,5)]);
imagechar($the_image, mt_rand(3,5), mt_rand(100,110), mt_rand(5,20), $RandomTextї4] ,$color_frontїmt_rand(1,5)]);
imagechar($the_image, mt_rand(3,5), mt_rand(120,135), mt_rand(5,20), $RandomTextї5] ,$color_frontїmt_rand(1,5)]);
//Now we send the picture to the Browser
header(\"e;Content-type: image/png\"e;);
imagepng($the_image);
?>Code: Select all
<?php
$passcode = md5($_POSTї'passcode'].\"e;secretpassphrase\"e;);
$controlhash = $_POSTї'hash'];
// Now we check, if the two strings are the same
if ($passcode == $controlhash) {
echo \"e;Well, thank you. You have entered the code correctly. <a href=index.php>Try again?</a>\"e;;
} else {
echo \"e;You haven´t entered the correct code. Please <a href=index.php>try again</a>!\"e;;
}
?>d11wtq |
Code: Select all
tags used in this instance due to a bug with theCode: Select all
tags and backslashes[/size][/color]