PHP user verification PHP+Ajax verification code to verify user login

WBOY
Release: 2016-07-27 16:56:17
Original
1064 people have browsed it

One advantage of using AJAX to verify user login is that the jump page does not need to be refreshed. In addition, it is safer to use the verification code, so I wrote it down after a while. A total of three files are used:

yz.php: The PHP file that generates the verification code. The verification code will be in the SESSION for comparison and call during login
index.php: The HTML file for user login
loginCheck .php:File to verify user login

The following is analyzed one by one:
yz.php file

<&#63;php
 session_start();

 //生成验证码图
 Header("Content-type: image/PNG");
 //长与宽
 $im = imagecreate(44,18);
 // 设置背景色:
 $back = ImageColorAllocate($im, 245,245,245);
 // 填充背景色:
 imagefill($im,0,0,$back);

 srand((double)microtime()*1000000);
 $vcodes;
 //生成4位数字
 for($i=0;$i<4;$i++){
  $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255));
  $authnum=rand(1,9);
  $vcodes.=$authnum;
  imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
 }

 //加入干扰象素
 for($i=0;$i<100;$i++){
  $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
  imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
 }
  
 ImagePNG($im);
 ImageDestroy($im);

 // 将四位的验证码保存在 SESSION 里,登录时调用对比
 $_SESSION["VCODE"]=$vcodes;
&#63;>

Copy after login

index.php: Note, do not take $_SESSION["VCODE"] in this file, otherwise it will If you take it a step later, the previous verification code will be displayed after refreshing. Just verify it in loginCheck.php. I hope that all the content will be helpful to everyone's study, and I also hope that everyone will support this site.


The above introduces the PHP user verification PHP+Ajax verification code to verify user login, including the content of PHP user verification. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!