Heim  >  Artikel  >  php教程  >  PHP生成可点击刷新的验证码简单示例,php生成验证码示例

PHP生成可点击刷新的验证码简单示例,php生成验证码示例

WBOY
WBOYOriginal
2016-06-13 08:39:27906Durchsuche

PHP生成可点击刷新的验证码简单示例,php生成验证码示例

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

html文件:

<html>
 <head>
   <title>验证码</title>
 </head>
  <script type="text/javascript">
    function yanzheng(){
      var im=document.getElementsByTagName("img");
      im[0].src="gd.php&#63;temp="+(new Date().getTime().toString(36));
    }
  </script>
 <body>
  <img  src="gd.php"/ alt="PHP生成可点击刷新的验证码简单示例,php生成验证码示例" ><a href="#" onclick="yanzheng()">换一张</a>
 </body>
</html>

验证码文件gd.php:

<&#63;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);
&#63;>

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

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn