This example for you to share a PHP write login verification code function for your reference, the specific content as follows
<?php session_start (); Set the cookie or Session function Esetcookie ($name, $str, $life =0) {//This function will string str
All lowercase strings make the validation code input case-insensitive----in submitting a form for session comparison also requires $_session[$name]=strtolower ($STR); //Get random characters This function distinguishes character case if case-insensitive can be added Strtolower function Domake_password ($len) {$chars = array (/* "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "s", "T", "U", "V", "w", "X", "Y", "Z" "," A "," B "," C "," D "," E "," F "," G "," H "," I "," J "," K "," L "," M "," N "," O "," P "," Q "," R "," S "," T "," U "," V ",
"W", "X", "Y", "Z", */"0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
$charsLen = count ($chars)-1;
Shuffle ($chars);//Disturb the array $output = "";
For ($i =0 $i < $len; $i + +) {$output. = $chars [Mt_rand (0, $charsLen)];//Get an array element} return $output; //Show Verification code function Showkey () {$key =domake_password (4);//Get random value $set =esetcookie ("Checkkey", $key);
Whether the random value is written to a cookie or session/is supported by the GD library if (function_exists ("imagejpeg")) {Header ("content-type:image/jpeg");
$img =imagecreate (47,20);
$blue =imagecolorallocate ($img, 102,102,102);
$white =imagecolorallocate ($img, 255,255,255);
$black =imagecolorallocate ($img, 71,71,71);
Imagefill ($img, 0,0, $blue);
Imagestring ($img, 5,6,3, $key, $white);
For ($i =0 $i <90; $i + +)//Add interference pixel {Imagesetpixel ($img, Rand ()%70,rand ()%30, $black);
} imagejpeg ($IMG);
Imagedestroy ($IMG);
} elseif (Function_exists ("Imagepng")) {header ("content-type:image/png");
$img =imagecreate (47,20);
$blue =imagecolorallocate ($img, 102,102,102);
$white =imagecolorallocate ($img, 255,255,255);
$black =imagecolorallocate ($img, 71,71,71);
Imagefill ($img, 0,0, $blue);
Imagestring ($img, 5,6,3, $key, $white);
For ($i =0 $i <90; $i + +)//Add interference pixel {Imagesetpixel ($img, Rand ()%70,rand ()%30, $black);
} imagepng ($IMG);
Imagedestroy ($IMG);
} elseif (Function_exists ("Imagegif")) {header ("content-type:image/gif");
$img =imagecreate (47,20); $blue =imagecolorallocate ($img, 102,102,102);
$white =imagecolorallocate ($img, 255,255,255);
$black =imagecolorallocate ($img, 71,71,71);
Imagefill ($img, 0,0, $blue);
Imagestring ($img, 5,6,3, $key, $white);
For ($i =0 $i <90; $i + +)//Add interference pixel {Imagesetpixel ($img, Rand ()%70,rand ()%30, $black);
} imagegif ($IMG);
Imagedestroy ($IMG);
} elseif (Function_exists ("Imagewbmp")) {header ("content-type:image/vnd.wap.wbmp");
$img =imagecreate (47,20);
$blue =imagecolorallocate ($img, 102,102,102);
$white =imagecolorallocate ($img, 255,255,255);
$black =imagecolorallocate ($img, 71,71,71);
Imagefill ($img, 0,0, $blue);
Imagestring ($img, 5,6,3, $key, $white);
For ($i =0 $i <90; $i + +)//Add interference pixel {Imagesetpixel ($img, Rand ()%70,rand ()%30, $black);
} imagewbmp ($IMG);
Imagedestroy ($IMG);
else {//does not support Authenticode header ("content-type:image/jpeg\r\n");
Header ("pragma:no-cache\r\n");
Header ("cache-control:no-cache\r\n");
Header ("expires:0\r\n");
$fp = fopen ("Data/vdcode.jpg", "R");
} showkey ();?>
The above is the entire content of this article, I hope that you learn PHP programming help.