private $height = '20',imagecolorallocate($im,如果要生成其它类型的验证码,private $width = '80' 有97%新玩家认为php验证码识别代码(php登录验证码实现)值得一读!

{image}

4条解答

一.本人初学PHP有没有的图形验证码推荐

PHP生成图形验证码的示例代码:


session_start();

// 设置验证码的宽和高

$width = 120;

$height = 40;

// 生成局游一个随机数作为验证码

$code = rand(1000, 9999);

// 将验证码保存到Session中

$_SESSION['captcha_code'] = $code;

// 创建一个图像资源

$image = imagecreatetruecolor($width, $height);

// 随机生成颜色

$bg_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));

$text_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));

$line_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));

// 填充背高纯景色

imagefill($image, 0, 0, $bg_color);

// 画干扰线

for ($i = 0; $i < 5; $i++) {

imageline($image, rand(0, $width / 2), rand(0, $height), rand($width / 2, $width), rand(0, $height), $line_color);

}

// 将验证码绘制到图像上

$font = ''; // 字体文件路径,请根据实际文件路径修改

$font_size = 20;

$text_box = imagettfbbox($font_size, 0, $font, $code);

$text_width = $text_box[2] - $text_box[0];

$text_height = $text_box[3] - $text_box[1];

$x = ($width - $text_width) / 2;

$y = ($height - $text_height) / 2 + $text_height;

imagettftext($image, $font_size, 0, $x, $y, $text_color, $font, $code);

// 发送图像内容并释放资源

header('Content-Type: image/png');

imagepng($image);

imagedestroy($image);


以上代码生成的图形验证码是四位数,其中包含随机生成的数值和干扰线。请注意的字体文件路径必须戚腊咐根据实际情况进行修改。如果要生成其它类型的验证码 ,可以根据需要修改代码 。

二.php的验证码代码

谁能提供详细又完整的又没有错误的验证代码?百度和gole的代码没有一个正确的。郁闷死/
类说明:
使用时,可按自己的需要设置输出图片的宽度和高度,以及要产生的验证码个数和干扰部分;
使用时 ,只需要将validate实例化,然后调用show_image()可生即可生成验证码。
获取验证码的方法是在其它页面 首先开户session_start(),然后直接使用$_SESSION['code']即可;
注意,大多数新手可能会遇到一个问题 ,就是$_SESSION['code']的值总是要慢一拍,用户在输入验证码点提交后,
session的值才会被刷新 ,这样使用不会有错,如果直接用JS去获取得取到的是上次的产生的.
最后:该类由游天小虾制作,您可以不保留此信息 ,可任意传播 ,如果您对本类有什么提意,
可发关邮件到:yiuked@
或者加入我们的网页制作交流群(聚义堂)
/
class validate {
private $width = '80';//验证码的宽度
private $height = '20';//验证码的高度
private $randcode = '';//验证码, 无需赋值,后面会随机生成
private $num = '4';//验证码的字数
private $interferon = '80';//干扰素数量
private $line ='2';//线条干扰条数
private $im = '';//无需赋值 ,图片自动生成/

输入网页类型
/
private function conten_type(){
header("Content_type:image/gif");
}
/

打开session
/
private function session_star(){
session_start();
}/

产生随机数
/
private function random(){
$this->randcode = strtoupper(substr(md5(rand()),0,$this->num));
return $this->randcode;
}
/

置障session的值
/
private function resession(){
$_SESSION['code'] = $this->randcode;
}
/

产生验证图片
/
private function create_image(){
$this->im = imagecreate($this->width,$this->height);
imagecolorallocate ($this->im, rand(50,60), rand(150,200),rand(230,250));
return $this->im;
} /

产生干扰素
/
private function create_interferon(){
for($i=0;$i<$this->interferon;$i++){
$infcolor = imagecolorallocate($this->im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($this->im,rand(0,80),rand(0,20),$infcolor);
} } /

产生干扰线条
/
private function create_line(){
for($j=0;$j<$this->line;$j++){
$lineColor = imagecolorallocate($this->im,rand(0,255),rand(0,255),rand(0,255));
imageline($this->im,rand(0,80),rand(0,20),rand(0,80),rand(0,20),$lineColor);
}
} /

写入字符
/
private function read_text(){
for($i=0;$i<$this->num;$i++){
$textColor = imagecolorallocate($this->im,rand(0,100),rand(0,100),rand(0,100));
$x = rand(($this->width/$this->num$i),($this->width/$this->num)($i+1)-10);
$y = rand(2,$this->height-13);
imagechar($this->im,rand(4,5),$x,$y,$this->randcode[$i],$textColor);
} } /

输出验证码图片
**/
public function show_image(){
$this->session_star();
$this->conten_type();
$this->random();
$this->resession();
$this->create_image();
$this->create_interferon();
$this->create_line();
$this->read_text();
imagepng($this->im);
imagedestroy($this->im);
}} $va = new validate(); $va->show_image();
?>

三.p呼际普hp的图片验证码代码

这个是phpcms的验证码,经过十几万个网站经验的,非常好用 session_start(); $enableg 范好作换亚婷省但些 d = 1; //判断图像处理函数是否存在 $funcs = array('imagec 室费价神自 reatetruecolor360问答','imagecolorallocate' 图吗短设微情但除施族洋 ,'imagefill','imagestring','imageline 风微民稳异信族使向未 ','imagerotate','imagedestroy','imagecolorallocatealpha','imageelli 地易够组找因尼城脸 pse','imagepng'); foreach($funcs as $func) { if(!function_exists($func)) { $enableg可轻洋死卷研d = 0; break; } } ob_clean(); //清理缓冲 if($enablegd) { //create captcha $consts = 'cdfgkmnpqrstwxy'; $vowels = 'aek23 武刻伤架印确史界著 '; for ($x = 0; $x < 6; $x++) { $const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1); //获取$consts中的一个随机数 $vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1); //获取$vowels中的一个随机数 } $radom 轴斯酒厚 string = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vo 雨同斤 w[3] . $const[4]; $SESSION['checkcode'] = $string = s _预滑乎赶 ubstr($radomstring,0,4); //显示4声报析象温宜北控个字符 $imageX = strlen($radomstring) 点职杂款条适办 8; //图像的宽 $imageY = 20;//图像的高 $im = imagecreatetrueco 零苦孙教体示讲七 lor($imageX,$imageY); //新建一个真彩色图像 //creates two variables to s标助tore color $background = imagecolorallocate($im, rand(180, 斯质剧者关石 250), rand(180, 250), rand(180, 250)); //背景色 $foregroundArr = arra 和拿品乐知守说 y(imagecolo 都参但理卷耐某弦合 rallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)), imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)), imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)), imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255)) ); $foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80); //分配颜色并说明透明度 $middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160)); //中间背景 $middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80); //中间背景2 //与左上角的颜色相同的都会被填充 imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254)); //往图像上写入文字 imagettftext($im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/', $string[0]); imagettftext($im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/', $string[1]); imagettftext($im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/', $string[2]); imagettftext($im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/', $string[3]); //画边框 $border = imagecolorallocate($im, 133, 153, 193); imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border); //画一些随机出现的点 $pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255)); for ($i=0;$i<80;$i++) { imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol); } //画随机出现的线 for ($x=0; $x<9;$x++) { if(mt_rand(0,$x)%2==0) { imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, )); //画线 imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2); //画椭圆 } else { imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, )); imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground); } } //output to browser header("content-type:image/png\r\n"); imagepng($im); imagedestroy($im); } else { $files = glob(XINCHENG_ROOT.'images/checkcode/.jpg'); if(!is_array($files)) die('请检查文件目录完整性:/images/checkcode/'); $checkcodefile = $files[rand(0, count($files)-1)]; //随机其中一个文件 $_SESSION['checkcode'] = substr(basename($checkcodefile), 0, 4); //获得文件名 header("content- type:image/jpeg\r\n"); include $checkcodefile; } ?>

四.php后台管理员用户验证代码

PHP+MY-SQL ,数据库名:login,表名:admin (username:admin, password:admin ) 用户: 密码: 请帮我把用户名与密码验证代码写下,如果验证成功的话 ,跳转的页面是,最好能解释下每行代码,谢谢!
这个是登录的界面 ,都是HTML,没什么好解释的

用户:
密码:

php后台管理员用户验证代码,可以进去搜一下 ,想复制怕有版权问题 ,谢谢采纳 。
阜阳86文章阅读网 /
阜阳86论坛 /

设置?

本文版权归趣快排SEO www.SeogurUblog.com 所有,如有转发请注明来出,竞价开户托管,seo优化请联系QQ▶61910465