PHP编写登录验证码功能附调用方法

上传人:cn****1 文档编号:511492737 上传时间:2023-07-31 格式:DOC 页数:3 大小:27KB
返回 下载 相关 举报
PHP编写登录验证码功能附调用方法_第1页
第1页 / 共3页
PHP编写登录验证码功能附调用方法_第2页
第2页 / 共3页
PHP编写登录验证码功能附调用方法_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《PHP编写登录验证码功能附调用方法》由会员分享,可在线阅读,更多相关《PHP编写登录验证码功能附调用方法(3页珍藏版)》请在金锄头文库上搜索。

1、本文实例为大家分享了一个PHP 写的登录验证码功能,供大家参考,具体内容如下ShowKey.php<?phpsession_start();/设置COOKIE或Sessionfunction esetcookie($name,$str,$life=0)/本函数将字符串str全部变小写字符串使验证码输入不区分大小写- 在提交表单进行 session 比较同样需要次函数转化 $_SESSION$name=strtolower($str);/获取随机字符此函数区分字符大小写如果不区分大小写可加入函数strtolowerfunction domake_password($len)&nb

2、sp;   $chars = array(     /*a, b, c, d, e, f, g, h, i, j, k,      l, m, n, o, p, q, r, s, t, u, v,      w, x, y, z, A, B, C, D, E, F, G,      H, I, J, K, L, M, N, O, P, Q, R,      S, T, U, V, W, X, Y, Z,*/ 0, 1, 2,&

3、nbsp;     3, 4, 5, 6, 7, 8, 9   );   $charsLen = count($chars) - 1;   shuffle($chars);/将数组打乱  $output = ;   for ($i=0; $i<$len; $i+)        $output .= $charsmt_rand(0, $charsLen); /获得一个数组元素     return $outpu

4、t; /显示验证码function ShowKey() $key=domake_password(4);/ 获取随机值 $set=esetcookie(checkkey,$key);/ 将随机值写入cookie 或 session / 是否支持 gd 库 if(function_exists(imagejpeg)    header (Content-type: image/jpeg);  $img=imagecreate(47,20);  $blue=imagecolorallocate($i

5、mg,102,102,102);  $white=ImageColorAllocate($img,255,255,255);  $black=ImageColorAllocate($img,71,71,71);  imagefill($img,0,0,$blue);  imagestring($img,5,6,3,$key,$white);  for($i=0;$i<90;$i+) /加入干扰象素     imagesetpixel($img,rand()%70,rand()%30,$black); &nbs

6、p;   imagejpeg($img);  imagedestroy($img);  elseif (function_exists(imagepng)   header (Content-type: image/png);  $img=imagecreate(47,20);  $blue=imagecolorallocate($img,102,102,102);  $white=ImageColorAllocate($img,255,255,255);  $black=ImageColorA

7、llocate($img,71,71,71);  imagefill($img,0,0,$blue);  imagestring($img,5,6,3,$key,$white);  for($i=0;$i<90;$i+) /加入干扰象素     imagesetpixel($img,rand()%70,rand()%30,$black);     imagepng($img);  imagedestroy($img);  elseif (function_exists(image

8、gif)    header(Content-type: image/gif);  $img=imagecreate(47,20);  $blue=imagecolorallocate($img,102,102,102);  $white=ImageColorAllocate($img,255,255,255);  $black=ImageColorAllocate($img,71,71,71);  imagefill($img,0,0,$blue);  imagestring($img,5,6,3,$k

9、ey,$white);  for($i=0;$i<90;$i+) /加入干扰象素     imagesetpixel($img,rand()%70,rand()%30,$black);     imagegif($img);  imagedestroy($img);  elseif (function_exists(imagewbmp)    $img=imagecreate(47,20);  $blue=imagecolorallocate($img,102

10、,102,102);  $white=ImageColorAllocate($img,255,255,255);  $black=ImageColorAllocate($img,71,71,71);  imagefill($img,0,0,$blue);  imagestring($img,5,6,3,$key,$white);  for($i=0;$i<90;$i+) /加入干扰象素     imagesetpixel($img,rand()%70,rand()%30,$black);   &nb

11、sp; imagewbmp($img);  imagedestroy($img);  else   / 不支持验证码  header(content-type:image/jpegrn);  header(Pragma:no-cachern);  header(Cache-Control:no-cachern);  header(Expires:0rn);  $fp = fopen(data/vdcode.jpg,r);  ShowKey();?>调用方法:代码如下:<imgsrc=ShowKey.phpname=KeyImgid=KeyImg onClick=KeyImg.src=ShowKey.php?+Math.random()> 以上就是本文的全部内容,希望对大家学习php 程序设计有所帮助。

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号