test.PHP
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<?php
header( 'Content-Type:image/jpeg' );
$img = imagecreatetruecolor(100, 40);
$black = imagecolorallocate( $img , 0x00, 0x00, 0x00);
$green = imagecolorallocate( $img , 0x00, 0xFF, 0x00);
$white = imagecolorallocate( $img , 0xFF, 0xFF, 0xFF);
imagefill( $img ,0,0, $white ); //生成随机的验证码
$code = '' ;
for ( $i = 0; $i < 4; $i ++) { $code .= rand(0, 9); }
imagestring( $img , 5, 10, 10, $code , $black );
//加入噪点干扰
for ( $i =0; $i <50; $i ++) {
imagesetpixel( $img , rand(0, 100) , rand(0, 100) , $black );
imagesetpixel( $img , rand(0, 100) , rand(0, 100) , $green );
} //输出验证码 header("content-type: image/png");
imagepng( $img );
imagedestroy( $img );
?>
|
test2.php
?
1
2
3
4
5
6
7
8
9
|
<script type= "text/javascript" >
function shuaxin()
{
document.getElementById( 'code' ).src = "test.php?" +Math.random();
}
</script>
<input type= "text" ><br />
<img id= "code" src= "test.php" onclick= "shuaxin()" />
<span onclick= "shuaxin()" >看不清?</span><br />
|
如下图所示:
总结
以上所述是小编给大家介绍的PHP使用GD库制作验证码的方法(点击验证码或看不清会刷新验证码),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对快网idc网站的支持!
原文链接:http://blog.csdn.net/ougexingfuba/article/details/77185704
相关文章
猜你喜欢
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
Linux Kernel 5.10.1紧急发布:修复两处存储代码BUG
2025-05-27 101 -
2025-05-27 87
-
2025-05-29 69
-
2025-06-04 65
-
2025-05-29 42
热门评论