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?