PHP如何生成可点击刷新的验证码
这篇文章给大家分享的是有关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如何生成可点击刷新的验证码”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!