PHP生成可点击刷新的验证码简单示例
author:一佰互联 2019-04-27   click:175

本文实例讲述了PHP生成可点击刷新的验证码。分享给大家供大家参考,具体如下:

html文件:

<html>
 <head>
   <title>验证码</title>
 </head>
  <script type="text/javascript">
    function yanzheng(){
      var im=document.getElementsByTagName("img");
      im[0].src="gd.php?temp="+(new Date().getTime().toString(36));
    }
  </script>
 <body>
  <img src="gd.php"/><a href="#" onclick="yanzheng()">换一张</a>
 </body>
</html>

验证码文件gd.php:

<?php
$im=imagecreate(50,20);
$b=imagecolorallocate($im,0,0,0);
$w=imagecolorallocate($im,255,255,255);
$mask="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$text="";
for($i=1;$i<=4;$i++){
  $index=rand(0,61);
  $text.=$mask{$index};
}
imagestring($im,3,rand(10,20),rand(0,10),$text,$w);
header("Content-type:image/jpeg");
imagejpeg($im);
?>

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP图形与图片操作技巧汇总》、《php文件操作总结》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。