1 / 9
文档名称:

PHP验证码.doc

格式:doc   页数:9页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

PHP验证码.doc

上传人:xxj16588 2016/7/23 文件大小:0 KB

下载得到文件列表

PHP验证码.doc

文档介绍

文档介绍:PHP 验证码刚学 PHP 的时候, 弄个验证码, 有点乱哈。找了几个来看, 原理都差不多,放上来给大家参考下。觉得可以的话,要顶哦! PHP 验证码实例一: <?php //ce shi:<input type="text" name="checkCode" size="10" /> //<img src="?act=yes" align="middle"> session_start();// 开启 session $randval; for($i = 0; $i<4; $i++){ // 产生 A-Z 之间的 ASCII 随机数$randstr = mt_rand(ord('a'), ord('z'));//ord($str) 返回字符的 ASCII $randv = mt_rand(0, 10);// 包括 0和 10 global $randval; // 产生 0-9 之间的随机数 if($randv %2 == 0){// 如果是偶数, 连接数字$randval .= mt_rand(0, 9); }else{// 否则奇数连接字符,用 chr 获取$randval .= chr($randstr);//chr() 返回相对应于 ascii 所指定的单个字符。//$randval .= mt_rand(0, 9); }} $_SESSION["randval"] = $randval; $intheight = 18;// 验证码背景图的高$intwidth = 50;// 验证码背景图的宽, 可相应修改$img = imagecreatetruecolor($intwidth, $intheight); $fontcolor = imagecolorallocate($img, 255, 0, 0); $backcolor = imagecolorallocate($img, 255, 255, 255); imagefill($img, 0, 0, $backcolor); // 画线 imageline($img, mt_rand(0,$intwidth/3), mt_rand(0,$intheight/3), mt_rand($intwidth/3,$intwidth), mt_rand($intheight/3,$intheight), $fontcolor); imageline($img, mt_rand($intwidth/3, $intwidth), mt_rand(0, $intheight/3), mt_rand(0, $intwidth/3), mt_rand(0, $intheight/3), $fontcolor); // 添加 img 里边的文字信息 imagestring($img, 8, mt_rand(0, $intwidth - strlen($randval) * 10), mt_rand(0, $intheight-12), $randval, $fontcolor); imagegif($img); imagedestroy($img); ?> PHP 验证码实例二: <?php Header("Content-type: image/gif"); $border = 0; //