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 );
?>
Reply to discussion (solution)
Get the header ('content-type: image/png ') to the beginning.
Comment out the header and check whether an error is returned.
The header ('content-type: image/png '); returns 500 at the beginning, and the Firefox prompt:
The image "http: // localhost/captcha. php" cannot be displayed due to its own problems
This prompt is not displayed when you fail to get the front.
In addition, if you note this sentence "$ _ SESSION ['pass _ phrase '] = SHA ($ pass_phrase);", it can still be displayed.
If you disable the header, the error 500 is returned:
GET captcha. php
500 Internal Server Error
Localhost
0 B
127.0.0.1: 80
Original response 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, 03 Nov 2013 12:16:16 GMT
Expires Thu, 19 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
Original request 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 );
Changed:
$ _ SESSION ['pass _ phrase '] = SHA1 ($ pass_phrase );
What about it?
SHA () is the MySQL function, and sha1 is the PHP function. thank you.