php使用GD库制作验证码,点击验证码或看不清会刷新验证码
2017-08-15 11:27
495 查看
这是利用GD库生成验证码的页面
test.php
<?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
<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 />
如下图所示:
test.php
<?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
<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库制作验证码的方法(点击验证码或看不清会刷新验证码)
- PHP学习笔记之使用GD库制作验证码(一)
- PHP验证码 实现点击刷新
- [php] 点击刷新验证码
- PHP使用GD库画简单的验证码
- 学习ThinkPHP3.2.2:video12,解决点击“看不清”刷新验证码问题
- yourphp点击刷新验证码
- php生成验证码,点击可刷新的实例
- php中使用GD库做验证码
- jsp使用验证码及验证码的点击刷新功能的实现
- PHP 使用GD库生成验证码 在图像上绘制汉字
- PHP学习笔记(6)js点击刷新验证码
- 使用php制作验证码
- PHP生成可点击刷新的验证码简单示例
- php实现点击可刷新验证码
- 用PHP生成验证码可以进行点击刷新
- 使用php制作验证码技术
- php 不刷新页面,点击刷新验证码
- php实现点击可刷新验证码
- ThinkPHP第九天(在Admin分组中配置__PUBLIC__,$POST异步传输,import使用方法,验证码点击刷新方法,Create方法作用)