Image verification code generation application example_PHP tutorial

WBOY
Release: 2016-07-13 16:59:24
Original
782 people have browsed it

A simple PHP program to generate graphic verification codes. The example tells you how to use this verification program. You can refer to it if you need it.

The code is as follows
 代码如下 复制代码

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'];
}
}
}
?>



   


Copy code

 代码如下 复制代码

session_start();


for($i=0;$i<4;$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);
?>


 

session_start();//Open session
if(isset($_POST['check']))
{
if($_POST['check'])
{
if($_POST['check']==$_SESSION['check_pic'])
{
echo "Verification code is correct".$_SESSION['check_pic'];
}
else
{
echo "Verification code error".$_SESSION['check_pic'];
}
}
}
?>





index.php verification code generation program

The code is as follows Copy code
session_start();
for($i=0;$i<4;$i++) //Four-digit verification code
{@$rand.=dechex(rand(1,15));//Generate random numbers first, then convert decimal to hexadecimal, pay attention to "."
}
$_SESSION['check_pic']=$rand;
$im=imagecreatetruecolor(100,30);//Create image
$bg=imagecolorallocate($im,0,0,0);//Set color
$wh=imagecolorallocate($im,255,255,255); imagestring($im,5,15,8,$rand,$wh);//Font, 1-6 header("Content-type: image/jpeg");//Output image
imagejpeg($im);
?>
http://www.bkjia.com/PHPjc/631328.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631328.htmlTechArticleA simple PHP program to generate graphic verification codes. The example tells you how to use this verification program. There are You can refer to it if needed. The code is as follows Copy code ?php tutorial session_...
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