Verification Code
<?php
/******************************************
Authentication Code Picture Generation file
Programmed by surfchen,http://yubeinet.com
The following define parts can be modified by themselves
******************************************/
Define ("Con_number", 5)//number of characters produced
Define ("Con_image_width", 100);//Wide Chart
Define ("Con_image_height", 20);//Tugau
Define ("Con_image_string", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");/the validation string to be built contains characters
Header ("content-type:image/png")//Output image header information
Session_Start ();
if ($_session[' num '])
{
unset ($_session[' num ']);/Logout last Picture verification code
}
$im =imagecreate (con_image_width,con_image_height);//Create Image
$black =imagecolorallocate ($im, 0,0,0);//Create a black marker
$white =imagecolorallocate ($im, 255,255,255);//Create white marker
$gray =imagecolorallocate ($im, 200,200,200);//Set up a gray marker
Imagefill ($im, 86,30, $black);//Fill image
For ($i =0 $i <500; $i + +)
{
$randcolor =imagecolorallocate ($im, Rand (100,255), Rand (100,255), Rand (100,255))//Create a random image color marker
Imagesetpixel ($im, Rand (0,con_image_width), Rand (0,con_image_height), $randcolor)////using the marker strokes established on the previous line, the coordinates of the points are random
}
For ($i =0 $i <6; $i + +)
{
Imageline ($im, Rand (0,con_image_width), Rand (0,con_image_height), Rand (0,con_image_width), Rand (0,con_image_height ), $gray);//Draw lines with random coordinates
}
For ($i =0 $i <=CON_number; $i + +)
{
$authnum. =substr (Con_image_string,rand (0,61), 1);//establish validation string
}
$_session[' num ']= $authnum;//write String to session for verification
Imagestring ($im, 5,10, 0, $authnum, $white);//write String to Picture
Imagepng ($im);//Output picture
Imagedestroy ($im);//Logoff picture resource
Exit ();//Terminate script
Mssql_init
?>
?
Ob_start ()
?>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> implementation of verification diagram function [gd+session]</title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<meta http-equiv= "Content-language" content= "ZH-CN"/>
<meta name= "generator" content= "EditPlus"/>
<meta name= "Author" content= "Surfchen"/>
<meta name= "keywords" content= "yubeinet.com,php,mysql,javacript,xhtml,xml,wml,svg"/>
<meta name= "description" content= "use GD and session to implement verification diagram in PHP"/>
<link rel= "stylesheet" href= "Index.css" type= "Text/css"/>
<body>
<?php
Session_Start ();
if (!empty ($_session[' num ']) and!empty ($_session[' num ']) and $_session[' num ']==$_post[' number ']) {
echo ' success ';
}elseif (!empty ($_post[' number ')) {
echo "Failed";
}
?>
<form method= "POST" action= "<?=$_server[' php_self ']?>" >
<input type= "text" name= "number"/>
<input type= "Submit" name= "Submission" value= "submitted"/>
</form>
</body>