About PHP code Generation verification Solution

Source: Internet
Author: User
About PHP Generation Verification code
The code is as follows
 Header ("Content-type:image/png");
Srand (Double) microtime () *1000000);//sow a seed that generates random numbers to facilitate the use of random number generation below
Session_Start ();//storing random numbers in session
$_session[' Authnum ']= "";
$im = Imagecreate (70,20) or Die ("Cant ' Initialize new GD image stream!"); Make picture background size
$black = Imagecolorallocate ($im, 0,0,0); Set of three Colors
$white = Imagecolorallocate ($im, 255,255,255);
$gray = Imagecolorallocate ($im, 200,200,200);

Imagefill ($im, 0,0, $gray); Using area Fill method, set (0,0)

Code method for generating mixed numbers and letters
$ychar = "0,1,2,3,4,5,6,7,8,9,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";
$list =explode (",", $ychar);
for ($i =0; $i <4; $i + +) {
$randnum =rand (0,35);
$authnum. = $list [$randnum];
}

while (($authnum =rand ()%100000) <10000); Generate a random number of five
Drawing a five-bit integer verification code into a picture
$_session[' Authnum ']= $authnum;

Imagestring ($im, 5, 3, $authnum, $black);
Use the col color to draw the string s to the x, y coordinates of the image represented by the image (0, 0 in the upper-left corner).
If the font is 1,2,3,4 or 5, use the built-in font

for ($i =0; $i <200; $i + +)//Add interfering pixels
{
$randcolor = Imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
Imagesetpixel ($im, Rand ()%70, Rand ()%30, $randcolor);
}
Imagepng ($im);
Imagedestroy ($im);
?>


And the GD library is open, but the picture is not generated. Please advise us
------Solution--------------------
Quote:
It's already open.

The code is OK, you first put $_session[' code ' = $verifyCode; Comment out it's not going to open the SESSION. It's probably your environment, and my test is fine.
  • 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.