PHP Verification Code

Source: Internet
Author: User
Tags imagejpeg

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 <?phpsession_start(); $arr = array(       ‘a‘,‘b‘,‘c‘,‘d‘,‘e‘,‘f‘,‘g‘,‘h‘,‘i‘,‘j‘,‘k‘,‘l‘,‘m‘,‘n‘,‘o‘,‘p‘,‘q‘,‘r‘,‘s‘,‘t‘,‘u‘,‘v‘,‘w‘,‘x‘,     ‘y‘,‘z‘,‘0‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘ ); $rand = ""; for($i=1;$i<=4; $i++){  <span style="background-color: rgb(192, 192, 192);">//随机产生4个由不同字母与数字组合成的验证码</span>     $rand .= $arr[rand(0,count($arr)-1)]; } $_SESSION[‘check_pic‘] = $rand; <span style="background-color: rgb(192, 192, 192);">//生成图片</span> $im = <span style="color: rgb(255, 0, 0);">imagecreatetruecolor</span>(100,30); <span style="background-color: rgb(192, 192, 192);">//生成颜色,当第一次调用生成颜色的方法,是生成背景颜色</span> $bg = <span style="color: rgb(255, 0, 0);">imagecolorallocate</span>($im,0,0,0); <span style="background-color: rgb(192, 192, 192);">//第二次调用这个方法,是可以生成图片上面的文字或其他样式的颜色 </span>$te =<span style="color: rgb(255, 0, 0);"> imagecolorallocate</span>($im,255,255,255);<span style="background-color: rgb(192, 192, 192);">//在图片上面生成文字</span> <span style="color: rgb(255, 0, 0);">imagestring</span>($im,rand(1,5),rand(3,70),rand(3,15),$rand,$te); <span style="background-color: rgb(192, 192, 192);">//要把php当成图片输出,必须给文件一个头申明</span><span style="color: rgb(255, 0, 0);">ob_clean()</span>; <span style="color: rgb(255, 0, 0);">header</span>("Content-type:image/jpeg"); <span style="background-color: rgb(192, 192, 192);">//最终生成图片</span> <span style="color: rgb(255, 0, 0);">imagejpeg</span>($im);?>

  

?
1 <span style="background-color: rgb(255, 102, 0);">imagecreatetruecolor(宽,高);    图片宽高</span>
?
1 <span style="background-color: rgb(255, 102, 0);">imagecolorallocate(图片,红,绿,蓝)    <span style="line-height: 1.5;">调用(三原色)生成颜色的方法,是生成背景颜色</span></span>
?
1 <span style="background-color: rgb(255, 102, 0);">imagestring<span style="line-height: 1.5;">(图片,字体大小,字所在的x轴,</span><span style="line-height: 1.5;">字所在的y轴,要显示的验证码,字体颜色</span><span style="line-height: 1.5;">)<br></span></span>
?
1 <span style="background-color: rgb(255, 102, 0);">header     要把php当成图片输出,必须给文件一个头申明</span>
?
1 <span style="background-color: rgb(255, 102, 0);">imagejpeg(图片)   生成图片</span>
?
1
?
1 <BR><BR><BR>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.