Ec (2); php instance verification code and login instance & lt ;? Phpsession_start (); if ($ act & quot; init & quot;) {& nbsp; Header (& quot; Content-type: imagepng & quot;); & nbsp; srand (microtime () * 100000); & nbsp; $ login_check_number script ec (2); script
Php instance verification code and login instance
Session_start ();
If ($ act = "init ")
{
Header ("Content-type: image/png ");
Srand (microtime () * 100000 );
$ Login_check_number = strval (rand ("1111", "9999 "));
Session_register ("login_check_number ");
// The SESSION is used to save the verification code.
// You can also use cookies.
// Setcookie ("login_check_number", $ login_check_number );
// Delete session_start () in the first line;
// COOKIE is not recommended because it 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 ();
}
/*
Usage:
Add
Add the following code to the login verification PHP page (Note: No output is allowed before the code is added because SESSION is used)
// $ 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 ("Incorrect verification code! ");
Die ();
}
*/
?>
A very comprehensive php Technology website, php enthusiasts have a wealth of articles and source code.
SESSION usage problems:
If the logon page is opened and the logon fails after the SESSION expires, the logon fails.
COOKIE usage problems:
The COOKIE is stored on the client, so it is better not to use the COOKIE.
For the VBB Forum, save checkNumber. php and modify the template content of the MYSQL database template data table titled logincode forumhome_logincode username_loggedout.
Then in the member. php
If ($ action = "login ")
Add later
// Check the verification code
Include_once ("./checkNumber. php ");
If ($ number! = $ Login_check_number | $ number = "")
{
Print ("Incorrect verification code! ");
Die ();
}