Home  >  Article  >  Backend Development  >  Use PHP to implement login verification code._PHP tutorial

Use PHP to implement login verification code._PHP tutorial

WBOY
WBOYOriginal
2016-07-13 11:00:091000browse

I saw DEV-CLUB implement verification code login verification a few days ago. It was implemented in PHP last night. Welcome everyone to discuss with me the principle of polygame@163.net
: generate a picture and save the characters displayed in the picture Go to SESSION. When logging in, determine whether the entered verification code is the same as the verification code in SESSION.
Demo address:
http://www.bingdu.net/bbs/
This is the generated verification Code and image files checkNumber.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 is used here to save the check code.
//Of course you can also use COOKIE
//setcookie("login_check_number",$login_check_number);
//Then change the session_start in the first line ()Delete;
//The use of COOKIE is not recommended, because using COOKIE does not allow for secure verification.
$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 ; checkNumber.php?act=init>
Add the following code to the login verification PHP page (note: there can be no output before adding the code because SESSION is used)
//$number is the verification you entered Code value
include_once("./checkNumber.php");
//Check check code
if($number != $login_check_number || empty($number))




http://www.bkjia.com/PHPjc/631835.html

www.bkjia.com

truehttp: //www.bkjia.com/PHPjc/631835.htmlTechArticleA few days ago I saw DEV-CLUB implementing verification code login verification. It was implemented in PHP last night. Welcome everyone to discuss with me the principle of polygame@163.net: generate a picture and save the words displayed in the picture...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn