本文实例讲述了PHP生成可点击刷新的验证码。分享给大家供大家参考,具体如下:
html文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<?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程序设计有所帮助。