PHP梨验证码
为什么下面的PHP代码会删除一些验证码图像,并允许其他几个图像保留在服务器上 伪代码PHP梨验证码,php,pear,Php,Pear,为什么下面的PHP代码会删除一些验证码图像,并允许其他几个图像保留在服务器上 伪代码 //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 radi
//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;
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表单
图像文件名在发送的HTML中可见 若你们使用固定的文件名,那个么机器人很容易建立一个和给定图像相关的单词目录,从而破坏了验证码的作用
因此,图像被复制到某个随机名称,显示在验证码页面上,然后被删除。我重新表述了最初的问题。
PHP
Require Once Text/Captcha.php
PEAR Capthca Options
/PHP
HTML
FORM
PHP
echo '<img src="' . sha1(session_id()) . '.png?' . time() . '" />';
/PHP
/FORM /HTML