Home > Backend Development > PHP Tutorial > php验证码图片

php验证码图片

WBOY
Release: 2016-06-23 13:29:39
Original
848 people have browsed it

这里我们介绍图片验证码的制作,有关字符验证码可以参考以下文章:

点击打开链接


图片验证码的制作分三步:

1.制作图片库

2.随机选取一张图片

3.输出图片内容


代码如下(这里为了方便我直接用的本地的图片,实际中会有大量图片,路径存放在数据库中):

<?phpsession_start ();$data = array(	dirname(__FILE__).'\pics\pic0.jpg'=>'狗',	dirname(__FILE__).'\pics\pic1.jpg'=>'猫',	dirname(__FILE__).'\pics\pic2.jpg'=>'鱼',	dirname(__FILE__).'\pics\pic3.jpg'=>'猪',	dirname(__FILE__).'\pics\pic4.jpg'=>'马',	dirname(__FILE__).'\pics\pic5.jpg'=>'驴',	dirname(__FILE__).'\pics\pic6.jpg'=>'鸟',	dirname(__FILE__).'\pics\pic7.jpg'=>'鸡',	dirname(__FILE__).'\pics\pic8.jpg'=>'鸭',	dirname(__FILE__).'\pics\pic9.jpg'=>'象',	);$rnd = rand(0,9);$img = dirname(__FILE__).'\pics\pic'.$rnd.'.jpg';$_SESSION['authcode'] = $data[$img];$content = file_get_contents($img);header("content-type: image/png");echo $content;
Copy after login


客户端:

<?phpif (isset($_REQUEST['authcode'])){	session_start();	if(($_REQUEST['authcode']) == $_SESSION['authcode']){		echo '<font color="#0000cc">输入正确';	}else{		echo '<font color="#cc0000"><b>输入错误</b></font>';	}	exit();}?>	<title></title>	
Copy after login

验证码图片:php验证码图片 换一个

图片内容:


结果图:




版权声明:本文为博主原创文章,未经博主允许不得转载。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template