php不错的验证码

添加时间:13-08-09 所属分类:PHP工具与代码
  转载自http://www.60ie.net/article/6/439.html

php的验证码其实网上有许多的,包括成熟的类也非常的多,而下面的这个是个再普通不过的php验证码了,只是为了让新手练习学习的,里面的源码倒不是很复杂,直接将其保存为.php,运行即可,而源码的实用方式也很简单,就是判断 $_SESSION['yanzheng'] 的值和自己提交的是否相同,如果相同那么就可以验证通过,不是很难的原理,就不多介绍了,运行一下试试看吧。
PHP代码

[code] <?php
session_start();
function rand_location() //获得4个不行等的相差20左右倍数的数 以免验证码重叠
{
$i = 0;
$location = array();
while ($i < 4) {
static $rand=0;
$rand +=20;
$location[$i] = $rand;
$i++;
}

return $location;

}
$range = '123456789zxcvbnmlkjhgfdsaqwertyuiopQWERTYUIOPASDFGHJKLMNBVCXZ';
for ($i = 0; $i < 4; $i++)
{
$rand[$i] = $range{rand(0, 42)};
}
$see=$rand;
$_SESSION['yanzheng']=implode("",$see);
$im = imagecreatetruecolor(100, 30);
$bg = imagecolorallocate($im, 180,239,90);
imagefilledrectangle($im, 0, 0, 150, 50, $bg);

/*for ($i = 0; $i < 200; $i++) //画点
{
$color = imagecolorallocate($im, 255,255,255);
imagesetpixel($im, rand(1, 100), rand(1, 30), $color);
}
*/

for ($i = 0; $i < 4; $i++) //画曲线
{
$color = imagecolorallocate($im, rand(1, 255), rand(1, 255), rand(1, 255));
imagearc($im, rand(5,90), rand(1, 10), rand(80, 100), rand(10, 30), rand(0,90), rand(0, 360), $color);
}

$location_x = rand_location(); //获得随机数
for ($i = 0; $i < 4; $i++) {
$color = imagecolorallocate($im, rand(178, 233),46, rand(46, 233));
imagettftext($im, 20, rand(0, 60), $location_x[$i], 27, $color, "C:\WINDOWS\Fonts\simhei.ttf",$rand[$i]);
}
header("Content-Type:image/jpeg");
imagejpeg($im);
?> [/code]

前篇:PHP上传文件代码,仅适合初学者,代码简洁易懂 后篇:济南市景区拍婚纱照收费调查:影楼钟爱免费...
发表我的评论


推荐文章   妈妈爸爸带娃对比照 画面不忍直视   山东人这样过端午,最全的习俗活动和节...   老师为学生补鞋照走红   四川无腿男子写千首情诗 感动女友父母   天上人间动漫网域名被盗及拿回始末(GoD...
随机文章   PHP curl函数模拟爬虫(操作cookie刷贴实...   php curl函数模拟浏览器抓取网站信息   PHP使用curl模拟用户登陆   MYSQL查询优化   php完全过滤HTML,JS,CSS等标签
广告

其他推荐

因为本站所有内容均转载自其它媒体,本意为公众提供免费服务,但并不代表本网赞同其观点,也不能对其真实性验证负责,如稿件版权单位或个人不想在本网发布,请与我联系,本人会立即将其撤除,谢谢.联系方式:atseashawk@163.com QQ:99289555