本文實例講述了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程序設計有所幫助。