Principle: create an image and keep the characters displayed in the image to the SESSION. when logging on, determine whether the entered verification code is the same as the verification code in the SESSION. this is a natural verification code and the checkNumber of the image file. php? Phpsession_start (); if ($ act = "init ")
Principle: A natural image is generated, and the characters displayed in the image are retained to the SESSION. when logging on, you can determine whether the entered verification code is the same as the verification code in the SESSION.
This is the checkNumber. php file of the inherent verification code and image.
Session_start ();
If ($ act = 'init ')
{
Header ('content-type: image/png ');
Srand (microtime () * 100000 );
$ Login_check_number = strval (rand ('20140901', '20160901 '));
Session_register ('login _ check_number ');
// Here the SESSION is applied to reserve the verification code.
// You can also use cookies.
// Setcookie ('login _ check_number ', $ login_check_number );
// Delete session_start () in the first line;
// The application COOKIE is not recommended because the application COOKIE cannot be used for security verification.
$ H_img = imagecreate (40, 17 );
$ C_black = ImageColorAllocate ($ h_img, 0, 0 );
$ C_white = ImageColorAllocate ($ h_img, 255,255,255 );
Imageline ($ h_img, 1, 1,350, 25, $ c_black );
Imagearc ($ h_img, 200, 15, 20, 20, 35,190, $ c_white );
Imagestring ($ h_img, 5, 2, 1, $ login_check_number, $ c_white );
ImagePng ($ h_img );
ImageDestroy ($ h_img );
Die ();
}
/*
Application method:
In the HTML file Enter the following code on the login verification PHP page (note: No output is allowed before the code is added, because the SESSION is applied)
// $ Number indicates the value of the verification code you entered.
Include_once ('./checkNumber. php ');
// Check the verification code
If ($ number! = $ Login_check_number | empty ($ number ))
{
Print ('check code is not accurate! ');
Die ();
}
*/
?>
Application SESSION Title:
If the logon page is opened and the logon fails after the SESSION expires, the logon fails.
Application COOKIE Title:
The COOKIE is retained by the customer, so it is better not to use it if the COOKIE is applied.
For the VBB Forum, after the checkNumber. php is retained, modify the template content of the MYSQL database template data table titled logincode forumhome_logincode username_loggedout.