PHP Instance Verification code and login instance
<?php
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");
Here is the session used to save the checksum code.
Of course, you can use cookies.
Setcookie ("Login_check_number", $login _check_number);
Then delete the first row of session_start ();
Cookies are not recommended because it is not safe to authenticate with cookies.
$h _img = imagecreate (40,17);
$c _black = imagecolorallocate ($h _img, 0,0,0);
$c _white = imagecolorallocate ($h _img, 255,255,255);
Imageline ($h _img, 1, 1, _black, $c);
Imagearc ($h _img, M, 190, $c _white);
Imagestring ($h _img, 5, 2, 1, $login _check_number, $c _white);
Imagepng ($h _img);
Imagedestroy ($h _img);
Die ();
}
/*
How to use:
Add <input type=text name=number maxlength=4>
In the Login Verification PHP page, add the following code (note: No output before adding code, because session is used)
$number is the value of the checksum code you entered.
Include_once ("./checknumber.php");
Check-Check Code
if ($number!= $login _check_number | | empty ($number))
{
Print ("Incorrect check code!");
Die ();
}
*/
?>
A very comprehensive PHP technology site, PHP enthusiasts have quite a wealth of articles and source code.
Problem with session:
If you open the landing page in the session after the expiration of the landing, then the landing will fail.
Problem with cookies:
Cookies are stored on the client, so you might as well not use cookies.
For VBB Forum. After saving the checknumber.php. Modify the MySQL database template The title of the datasheet is Logincode Forumhome_logincode username_loggedout Content.
And then in Member.php's
if ($action = = "Login")
After joining
/Check code
include_once ("./checknumber.php");
if ($number!= $login _check_number | | $number = = "")
{
print ("Incorrect check code!");
Die ();
}