Home > Backend Development > PHP Tutorial > PHP登录页面验证码的实现

PHP登录页面验证码的实现

WBOY
Release: 2016-06-23 13:25:23
Original
1644 people have browsed it

  打开Dreamweaver cs6,新建一个PHP站点:

先新建一个命名为111.php文件,双击编辑,清空Dreamweaver自动生成的HTML代码,如下;

最后在Dreamweaver CS6编辑器添加PHP代码,如下:

  session_start();

  header("Content-Type:image/png");  //设置页面的头信息输出为png图片$im=imagecreate(60,20);   //创建一个画布

  $im_color=imagecolorallocate($im,100,100,100);  //填充验证码背景为灰色

  for($i=0;$i

  {

  $line_color=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));

  imageline($im,rand(0,60),rand(0,20),rand(0,60),rand(0,20),$line_color);

  }

  //实用循环画四条随机颜色的干扰线

  $n=rand(1000,9999);

  $_SESSION["y"]=$n;

  $p=0;


  for($i=0;$i

  {

  $p=$p+10;

  $num=substr($n,$i,1);  //把验证码数字一个一个的取出来

  $num_color=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));

  imagettftext($im,rand(10,15),rand(-10,10),$p,rand(10,15),$num_color,"font1.ttf",$num);


  }

  //设置每个验证码数字不同的颜色,数字角度偏差和字体。

  imagepng($im);  //输出验证码

  imagedestroy($im); //释放内存

  ?>

然后,

新建login.php文件;

  用户名文本框昵称为name;

  密码文本框为;可以随便写

  验证码为;可以随便写

  表单的提交方式为post,提交到check.php。

end

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