PHP Verification Code pattern cannot be displayed

Source: Internet
Author: User
Tags sha1
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);
?>


Reply to discussion (solution)

Take the header (' Content-type:image/png ') and get to the front.

Comment out the header run the newspaper what error

Take the header (' Content-type:image/png '), get to the front or 500, and Firefox tip:
The image "http://localhost/captcha.php" cannot be displayed because of its own problem

I didn't get the tip when I got the front.
In addition, when you get to the front, if you note the phrase "$_session[' pass_phrase '" = SHA ($pass _phrase); ", you can still display the

Note the header or report 500:
GET captcha.php
Internal Server Error
localhost
0 B
127.0.0.1:80

Response header Information Raw header information
Cache-control No-store, No-cache, Must-revalidate, post-check=0, pre-check=0
Connection Close
Content-length 0
Content-type text/html
Date Sun, Geneva 12:16:16 GMT
Expires Thu, Nov 1981 08:52:00 GMT
Pragma No-cache
Server apache/2.2.25 (WIN32) php/5.3.27
X-powered-by php/5.3.27
Request header information Raw header information
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-encoding gzip, deflate
Accept-language zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Cache-control max-age=0
Connection keep-alive
Cookie Phpsessid=9e4i75adp4ahnpba6ieq1pinn0
Host localhost
User-agent mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) gecko/20100101 firefox/24.0

$_session[' pass_phrase ' = SHA ($pass _phrase);
Change to:
$_session[' pass_phrase '] = SHA1 ($pass _phrase);
It?

, SHA () is the function of MySQL, PHP is SHA1, thank you, give points

  • 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.