PHP verification code pattern cannot be displayed

Source: Internet
Author: User
The captcha below cannot be displayed in the PHP verification code pattern. 500 error is returned when the php file is running. & nbsp; the verification code pattern is not displayed. Note this sentence "$ _ SESSION ['pass _ phrase '] & nbsp; = & nbsp; SHA ($ pass_phrase); & nbsp; ", no error is reported and the pattern can be displayed. why? The pattern of the sessi PHP verification code is not displayed.
The following Error 500 is returned when the captcha. php file is running. the verification code pattern is not displayed.
After you note this sentence "$ _ SESSION ['pass _ phrase '] = SHA ($ pass_phrase);", no error is reported and the pattern can be displayed. why?
How can I modify the session information?

Session_start ();

// Set some important CAPTCHA constants
Define ('captcha _ numchars', 6); // number of characters in pass-phrase
Define ('captcha _ width', 100); // WIDTH of image
Define ('captcha _ height', 25); // HEIGHT of image

// Generate the random pass-phrase
$ Pass_phrase = "";
For ($ I = 0; $ I <CAPTCHA_NUMCHARS; $ I ++ ){
$ Pass_phrase. = chr (rand (97,122 ));
}

// Store the encrypted pass-phrase in a session variable
$ _ SESSION ['pass _ phrase '] = SHA ($ pass_phrase );

// Create the image
$ Img = imagecreatetruecolor (CAPTCHA_WIDTH, CAPTCHA_HEIGHT );

// Set a white background with black text and gray graphics
$ Bg_color = imagecolorallocate ($ img, 255,255,255); // white
$ Text_color = imagecolorallocate ($ img, 0, 0); // black
$ Graphic_color = imagecolorallocate ($ img, 64, 64); // dark gray

// Fill the background
Imagefilledrectangle ($ img, 0, 0, CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $ bg_color );

// Draw some random lines
For ($ I = 0; $ I <5; $ I ++ ){
Imageline ($ img, 0, rand () % CAPTCHA_HEIGHT, CAPTCHA_WIDTH, rand () % CAPTCHA_HEIGHT, $ graphic_color );
}

// Sprinkle in some random dots
For ($ I = 0; $ I <50; $ I ++ ){
Imagesetpixel ($ img, rand () % CAPTCHA_WIDTH, rand () % CAPTCHA_HEIGHT, $ graphic_color );
}
// Draw the pass-phrase string
Imagettftext ($ img, 18, 0, 5, CAPTCHA_HEIGHT-5, $ text_color, 'courier New Bold. ttf', $ pass_phrase );
// Output the image as a PNG using a header
Header ('content-type: image/png ');
Imagepng ($ img );

// Clean up
Imagedestroy ($ img );
?> Share:
------ Solution --------------------
Comment out the header and check whether an error is returned.
------ Solution --------------------
$ _ SESSION ['pass _ phrase '] = SHA ($ pass_phrase );
Changed:
$ _ SESSION ['pass _ phrase '] = SHA1 ($ pass_phrase );
What about it?

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.