Home > php教程 > php手册 > 图片验证码生成应用实例

图片验证码生成应用实例

WBOY
Release: 2016-06-13 10:03:38
Original
948 people have browsed it

一款简单的php生成图形验证码程序,实例告诉你了如何去使用这段验证程序,有需要的可以参考一下。

 代码如下 复制代码

session_start();//开启session
if(isset($_POST['check']))
{
if($_POST['check'])
 {
if($_POST['check']==$_SESSION['check_pic'])
 {
 echo " 验证码正确".$_SESSION['check_pic'];
 }
else
 {
 echo " 验证码错误".$_SESSION['check_pic'];
 }
}
}
?>


图片验证码生成应用实例
   


index.php验证码生成程序

 代码如下 复制代码

session_start();


for($i=0;$i {@$rand.=dechex(rand(1,15));//先生成随机数,再将十进制转十六进制,注意"."
}
$_SESSION['check_pic']=$rand;
 $im=imagecreatetruecolor(100,30);//创建图片
$bg=imagecolorallocate($im,0,0,0);//设置颜色
$wh=imagecolorallocate($im,255,255,255);

imagestring($im,5,15,8,$rand,$wh);//字体,1-6

header("Content-type: image/jpeg");//输出图片
imagejpeg($im);
?>


 

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template