Internship is to do a message, the message needs to verify the code.
PHP Verification code implementation, in fact, is the first random number, and then the drawing.
The key code is in validcode.php:
<?php
Header ("Content-type:image/png");
Open session
session_start ();
Random 4 digits
$code = "";
$arr = Array ();
For ($i =0 $i <4; $i + +) {
$arr [$i] = rand (0,9);
$code. = (String) $arr [$i];
}
Set into session, convenient than to
$_session["validcode"] = $code;
Start drawing
$width = m;
$height =;
$img = Imagecreatetruecolor ($width, $height);
Fill background color
$backcolor = imagecolorallocate ($img, 0,0,0);
Imagefill ($img, 0,0, $backcolor);
Gets a randomly darker color for
($i =0 $i <4; $i + +) {
$textcolor = imagecolorallocate ($img, Rand (50,180), Rand (50,180), Rand (50,180));
Imagechar ($img, 12,7+ $i *25,3, (String) $arr [$i], $textcolor);
Display Picture
imagepng ($img);
Destroy picture
Imagedestroy ($img);
? >
Then use a page, place the IMG tag, and introduce the verification code. Then use a label for the user to switch the verification code to prevent the situation from being seen.