PHP生成图片验证码

来源:互联网 发布:数据库配置文件加密 编辑:程序博客网 时间:2024/05/23 15:45

带干扰的图片验证码(包含像素和横线)__

1.php生成图片验证码

<?phperror_reporting(0);session_start();for($i=0;$i<5;$i++){$rand.=dechex(rand(0,15));//生成随即验证数_十六进制函数}$_SESSION[check_pic]=$rand;//保存用于比较

$im= imagecreatetruecolor(100,30); //新建一个真彩色图像

$bg=imagecolorallocate($im,0,0,0);//为图像分配色彩 调色板$te=imagecolorallocate($im,255,255,255);for($i=0;$i<3;$i++){$te1=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));imageline($im,0,rand(0,15),100,rand(0,30),$te1);//图片上划线}for($i=0;$i<200;$i++){imagesetpixel($im,rand()%100,rand()%30,$te1);//随即画像素}imagestring($im,rand(1,6),rand(3,50),rand(3,15),$rand,$te);//绘图函数header("Content-type:image/jpeg");//输出格式imagejpeg($im);?>

生成图像类似:


2.php 验证 验证码

<?phperror_reporting(0);session_start();if($_POST[check]){if($_POST[check]==$_SESSION[check_pic]){echo "验证码正确!".$_SESSION[check_pic];}else{echo "验证码错误!".$_SESSION[check_pic];}}?><form action="" method="post"><input type="text" name="check"/> <img src="2.php"/><input type="submit" value="submit"/> </form>


原创粉丝点击