PHP Verification Code pattern cannot be displayed

Source: Internet
Author: User
PHP Verification Code pattern cannot be displayed
The following captcha.php file runtime returns 500 error, does not display the CAPTCHA pattern
Note the phrase "$_session[' pass_phrase '" = SHA ($pass _phrase); "After, will not error and can display the pattern, what reason?"
How do I change the session to save 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, 0); Black
$graphic _color = imagecolorallocate ($img, 64, 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 < $i + +) {
Imagesetpixel ($img, rand ()% Captcha_width, rand ()% captcha_height, $graphic _color);
}
Draw the Pass-phrase string
Imagettftext ($img, 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 to:


------Solution--------------------
Comment out the header run the newspaper what error
------Solution--------------------
$_session[' pass_phrase ' = SHA ($pass _phrase);
Change to:
$_session[' pass_phrase '] = SHA1 ($pass _phrase);
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.