Home > Backend Development > PHP Tutorial > PHP生成验证码 第二弹,强势来袭

PHP生成验证码 第二弹,强势来袭

WBOY
Release: 2016-06-23 13:28:51
Original
815 people have browsed it

function getVerify()<br />{<br /><br />    session_start();<br />    ob_clean ();   //清除缓冲区    <br />    header("Content-type:image/png");<br /><br />    $img_width=40;<br />    $img_height=20;<br /><br />    srand(microtime()*100000);<br />    for($i=0;$i<4;$i++)<br />    {<br />        $new_number.=dechex(rand(0,15));<br />    }<br /><br />    $_SESSION[check_auth]=$new_number;<br />    $new_number=imageCreate($img_width,$img_height);//创建图象<br />    ImageColorAllocate($new_number,255,255,255);  //设置背景色为白色<br /><br />    for($i=0;$i<strlen($_SESSION[check_auth]);$i++)<br />    {<br />        $font=mt_rand(3,5);<br />        $x=mt_rand(1,1) + $img_width*$i/4;<br />        $y=mt_rand(1,$img_height/4);<br />        $color=imageColorAllocate($new_number,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200));//设置字符颜色<br />        imageString($new_number,$font,$x,$y,$_SESSION[check_auth][$i],$color);//输出字符<br />    }<br />    //将验证码存入$_SESSION中<br />    $_SESSION["verify"]=$_SESSION[check_auth];<br /><br />    ImagePng($new_number);<br />    ImageDestroy($new_number);<br /><br />}
Copy after login

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