不需要GD库的情况下实现验证码

不需要GD库的情况下实现验证码

 1   
 2//+-------------------------------------------------   
 3//| * 文件 validate_image.php   
 4//| * 功能 实现网站登陆验证码   
 5//| * 版本 1.0.0   
 6//| * 日期 2005-4-1   
 7//| * 作者 西北狼 QQ 500784 cokeyang at hotmail.com   
 8//| * 版权 http://www.adibaby.com [暂时关闭]   
 9//| * 使用方法:   
10//| 预先在支持GD库的做好一些图片,推荐使用GIF格式,文件名与图片里   
11//| 面的里面的数字一致,将图片放入一个文件夹。设置CONFIG里面的数据.   
12//| 引用

<img src="{ filepath }/validate_image.php"/>

 1//| 验证页面对比   
 2//| $_COOKIE['validate'] == md5($_POST['input'])   
 3//|==================CONFIG START===================   
 4$image_path="numimage";// 图片文件路径 后面没有'/'   
 5$image_ext ="gif";// 图片文件扩展名   
 6//===================CONFIG END=====================   
 7$imagelist = array();   
 8if ($handle =opendir($image_path)) {   
 9while (false !== ($file =readdir($handle))) {   
10$filename =explode(".",$file);   
11$imagelist[] = $filename[0];   
12unset($filename);   
13}   
14closedir($handle);   
15unset($imagelist[0]);   
16unset($imagelist[1]);   
17}   
18srand((float)microtime()*103E//| 引用

<img src="{ filepath }/validate_image.php"/>

 1//| 验证页面对比   
 2//| $_COOKIE['validate'] == md5($_POST['input'])   
 3//|==================CONFIG START===================   
 4$image_path="numimage";// 图片文件路径 后面没有'/'   
 5$image_ext ="gif";// 图片文件扩展名   
 6//===================CONFIG END=====================   
 7$imagelist = array();   
 8if ($handle =opendir($image_path)) {   
 9while (false !== ($file =readdir($handle))) {   
10$filename =explode(".",$file);   
11$imagelist[] = $filename[0];   
12unset($filename);   
13}   
14closedir($handle);   
15unset($imagelist[0]);   
16unset($imagelist[1]);   
17}   
18srand((float)microtime()*10000000);   
19$filename=$imagelist[array_rand($imagelist)];   
20setcookie("validate",md5($filename));   
21header('Content-type: application/'.$image_ext);   
22echo implode('',file($image_path."/".$filename.".".$image_ext));   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus