PHP Pear CAPTCHA
Why would the PHP code below, delete some CAPTCHA images and allow several other images to remain on the server?
psuedo-code
//process_form.php
PHP
session_start()
$radiobutton = '';
$captcha_set = false;
IF POST SUBMIT
IF empty text1 && empty text2
echo error msg, include HTML FORM
ELSE IF empty radiobtn
echo error msg, include HTML FORM
ELSE IF
isset POST[phrase] isstring POST[phrase] isset SESSION[phrase]
strlen POST[phrase] > 0 strlen SESSION[phrase] > 0
POST[phrase] == SESSION[phrase]
$captcha_set = true;
开发者_如何学Python if ($captcha_set)
{
unset($_SESSION['phrase']);
unlink(sha1(session_id()) . '.png');
}
SQL INSERT
ELSE
echo error msg, include HTML FORM
ELSE
include HTML FORM
/PHP
HTML FORM
PHP
Require Once Text/Captcha.php
PEAR Capthca Options
/PHP
HTML
FORM
PHP
echo '<img src="' . sha1(session_id()) . '.png?' . time() . '" />';
/PHP
/FORM /HTML
The image file name is visable in the sent HTML.
If you used fixed file names it would be too easy for a Robot to build up a catalogue of the words associated with a given image thus defeating the point of the CAPTCHA.
So the image is copied to some random name, displayed on the CAPTCHA page and then deleted.
精彩评论