现在大多数的网站论坛为了防止恶意的注册都带动态的验证码
但是大部分都是图片类的
做图片类的验证码要用到GD
现在又看到许多网站的验证码为 简单提问类的 如 2+3= 之类的 如下网站
http://www.w3pop.com/learn/view/doc/func_filesystem_fopen/这个基本的 思路以及原理是什么呢 ?
谁能给我个 代码 看看 哪怕是连接也好
在有就是请注意 查看http://www.w3pop.com/learn/view/doc/func_filesystem_fopen/
这个网页的源代码 是看不到 如2+3 的这个公式的 为什么呢 ?
但是大部分都是图片类的
做图片类的验证码要用到GD
现在又看到许多网站的验证码为 简单提问类的 如 2+3= 之类的 如下网站
http://www.w3pop.com/learn/view/doc/func_filesystem_fopen/这个基本的 思路以及原理是什么呢 ?
谁能给我个 代码 看看 哪怕是连接也好
在有就是请注意 查看http://www.w3pop.com/learn/view/doc/func_filesystem_fopen/
这个网页的源代码 是看不到 如2+3 的这个公式的 为什么呢 ?
原来跟图片类的差不多吧,服务器生成两个数字,输出到浏览器端
生成一个session验证并且返回算式信息到一个span里面
//checkNum.php
session_start();
function random($len)
{
$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
mt_srand();//配置乱数种子
$strs="";
for($i=0;$i<$len;$i++){
$strs.=$srcstr[mt_rand(0,35)];
}
/*
2 名 称:strtoupper
3 功 能:字串全转为大写\r
4 传回值:字串
5 语 法:strtoupper(string str);
6 说 明:本函式将字串 str 全部变大写字串。\r
7 范 例:
8 strtoupper("ab2cd4efg"); 结果为AB2CD4EFG
9 strtoupper("ab1cde4fg"); 结果为Ab1CDE4fg
10
11 */
return strtoupper($strs);
}
$str=random(4); //随机生成的字符串
$width = 50; //验证码图片的宽度
$height = 25; //验证码图片的高度
/*
Content-Type: xxxx/yyyy
Location: xxxx:yyyy/zzzz
Status: nnn xxxxxx
*/
@header("Content-Type:image/png");
$_SESSION["code"] = $str;
//echo $str;
$im=imagecreate($width,$height);
//背景色
$back=imagecolorallocate($im,0xFF,0xFF,0xFF);
//模糊点颜色
$pix=imagecolorallocate($im,187,230,247);
//字体色
$font=imagecolorallocate($im,41,163,238);
//绘模糊作用的点
mt_srand();
for($i=0;$i<1000;$i++)
{
imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);
}
imagestring($im, 5, 7, 5,$str, $font);
imagerectangle($im,0,0,$width-1,$height-1,$font);
imagepng($im);
imagedestroy($im);
$_SESSION["code"] = $str;session_destroy();
?>
//checkNum.php
session_start();
function random($len)
{
$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
mt_srand();//配置乱数种子
$strs="";
for($i=0;$i<$len;$i++){
$strs.=$srcstr[mt_rand(0,35)];
}
/*
2 名 称:strtoupper
3 功 能:字串全转为大写\r
4 传回值:字串
5 语 法:strtoupper(string str);
6 说 明:本函式将字串 str 全部变大写字串。\r
7 范 例:
8 strtoupper("ab2cd4efg"); 结果为AB2CD4EFG
9 strtoupper("ab1cde4fg"); 结果为Ab1CDE4fg
10
11 */
return strtoupper($strs);
}
$str=random(4); //随机生成的字符串
$width = 50; //验证码图片的宽度
$height = 25; //验证码图片的高度
/*
Content-Type: xxxx/yyyy
Location: xxxx:yyyy/zzzz
Status: nnn xxxxxx
*/
@header("Content-Type:image/png");
$_SESSION["code"] = $str;
//echo $str;
$im=imagecreate($width,$height);
//背景色
$back=imagecolorallocate($im,0xFF,0xFF,0xFF);
//模糊点颜色
$pix=imagecolorallocate($im,187,230,247);
//字体色
$font=imagecolorallocate($im,41,163,238);
//绘模糊作用的点
mt_srand();
for($i=0;$i<1000;$i++)
{
imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);
}
imagestring($im, 5, 7, 5,$str, $font);
imagerectangle($im,0,0,$width-1,$height-1,$font);
imagepng($im);
imagedestroy($im);
$_SESSION["code"] = $str;session_destroy();
?>