Principle: Generate a picture, and save the characters displayed in the picture to the session. When landing to determine whether the input check code and the session commander of the same code.
This is the file that generates the checksum code and the picture checknumber.php
<?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");
//这里是使用了SESSION来保存校验码.
//当然也可以用COOKIE
//setcookie("login_check_number",$login_check_number);
//然后将第一行的session_start()删除;
//不推荐使用COOKIE,因为使用COOKIE并不能进行安全的验证.
$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, 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();
}
/*
How to use:
Add the following code to the Login verification php page by adding <input Type=text name=number to the HTML file maxlength=4> (Note: cannot have output before adding code because session is used)
//$number 是你输入的校验码的值
include_once("./checkNumber.php");
//检验校验码
if($number != $login_check_number || empty($number))
{
print("校验码不正确!");
die();
}
*/
?>
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
//检验校验码
include_once("./checkNumber.php");
if($number != $login_check_number || $number == "")
{
print("校验码不正确!");
die();
}