如果 isset PHP 不起作用


if isset PHP not working?

好的,我试图设置一个验证码,但是有了这段代码,它就坏了。

if(isset($_POST["captcha"]))
    if($_SESSION["captcha"]==$_POST["captcha"])

当我没有它时,页面可以工作,但验证码允许不正确的提交通过。

解析错误:语法错误,意外的",期望第 71 行的/hermes/waloraweb085/b2027/moo.lutarinet/jointest.php 中的T_STRING或T_VARIABLE或T_NUM_STRING

<?php
$pagetitle = "Home";
$checkrank = 0;
include ($_SERVER['DOCUMENT_ROOT'].'/header.inc.php');
ECHO <<<END
<br><br>
<b><center><i><u>DO NOT</u> USE YOUR NEOPETS PASSWORD OR PIN NUMBER!!!</b></i></center>
<p>
?>

<?php session_start() ?> 
<center><P><FORM ACTION="join.pro.php" enctype="multipart/form-data" METHOD=POST>
   <table width="393" height="188" border="0" cellpadding="0" cellspacing="0">
       <td width="150">Username</td>
       <td width="243"><input type=text name="name" value="" size=32 maxlength=15></td>
     </tr>
     <tr>
       <td>Password</td>
       <td><input type=password name="pass1" VALUE="" maxlength=15></td>
     </tr>
     <tr>
       <td>Confirm Password</td>
       <td><input type=password name="pass2" VALUE="" size=32 maxlength=15></td>
     </tr>
     <tr>
       <td>Security Code (4 Diget Number)</td>
       <td><input type=password name="security" VALUE="" size=32 maxlength=4></td>
     </tr>
     <tr>
       <td>Email Address</td>
       <td><INPUT TYPE=text NAME="email" VALUE="" SIZE=32 maxlength=100></td>
     </tr>
     <tr>
       <td height="41" colspan="2" valign="middle"><p><p><center>
         By registering an account here you agree to all
         of our <A HREF="$baseurl/tos.php">Terms and
       Conditions</A>. You can also view our <A HREF="$baseurl/privacy.php">Privacy
   Policy</A>. 
       </center></p></td>
     </tr>
<tr><td align="center">CAPTCHA:<br>
    (antispam code, 3 black symbols)<br>
    <table><tr><td><img src="captcha.php" alt="captcha image"></td><td><input type="text" name="captcha" size="3" maxlength="3"></td></tr></table>
</td></tr>
<td height="27" colspan="2" valign="middle">
         <center><input type=submit name=Submit value="Register"></center>
       </td>
</table>
</form>
<?php
if(isset($_POST["captcha"]))
if($_SESSION["captcha"]==$_POST["captcha"])
{
    //CAPTHCA is valid; proceed the message: save to database, send by e-mail ...
    echo 'CAPTHCA is valid; proceed the message';
}
else
{
    echo 'CAPTHCA is not valid; ignore submission';
}
?>

<?php

END;


include ($_SERVER['DOCUMENT_ROOT'].'/footer.inc.php');

?>

验证码.php

<?php
session_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); 
function _generateRandom($length=6)
{
    $_rand_src = array(
        array(48,57) //digits
        , array(97,122) //lowercase chars
//      , array(65,90) //uppercase chars
    );
    srand ((double) microtime() * 1000000);
    $random_string = "";
    for($i=0;$i<$length;$i++){
        $i1=rand(0,sizeof($_rand_src)-1);
        $random_string .= chr(rand($_rand_src[$i1][0],$_rand_src[$i1][1]));
    }
    return $random_string;
}
$im = @imagecreatefromjpeg("http://sketchedneo.com/images/sitedesigns/captcha.jpg"); 
$rand = _generateRandom(3);
$_SESSION['captcha'] = $rand;
ImageString($im, 5, 2, 2, $rand[0]." ".$rand[1]." ".$rand[2]." ", ImageColorAllocate ($im, 0, 0, 0));
$rand = _generateRandom(3);
ImageString($im, 5, 2, 2, " ".$rand[0]." ".$rand[1]." ".$rand[2], ImageColorAllocate ($im, 255, 0, 0));
Header ('Content-type: image/jpeg');
imagejpeg($im,NULL,100);
ImageDestroy($im);
?>

帮忙请任何人?

第 71 行:if(isset($_POST["验证码"]))

第 72 行:if($_SESSION["验证码"]==$_POST["验证码"])

编辑:

你错过了END;

ECHO <<<END
<br><br>
<b><center><i><u>DO NOT</u> USE YOUR NEOPETS PASSWORD OR PIN NUMBER!!!</b></i></center><p>
END; // You forgot to include this

顺便说一下,session_start()应该是脚本中调用的第一件事,因为它需要在启动任何其他输出之前完成。

此外,尝试使用多行分支使大括号按顺序排列(使其更容易扫描):

if (isset($_POST["captcha"]))
{
    if ($_SESSION["captcha"] == $_POST["captcha"])
    {
        //CAPTHCA is valid; proceed the message: save to database, send by e-mail ...
        echo 'CAPTHCA is valid; proceed the message';
    }
    else
    {
        echo 'CAPTHCA is not valid; ignore submission';
    }
}
if(isset($_POST["captcha"]))
if($_SESSION["captcha"]==$_POST["captcha"])
{
    //CAPTHCA is valid; proceed the message: save to database, send by e-mail ...
echo 'CAPTHCA is valid; proceed the message';
}
else
{
    echo 'CAPTHCA is not valid; ignore submission';
}

如果...

if(isset($_POST['captcha']))
{
    if($_SESSION['captcha'] == $_POST['captcha'])
    {
        //CAPTHCA is valid; proceed the message: save to database, send by e-mail ...
        echo 'CAPTHCA is valid; proceed the message';
    }
    else
    {
        echo 'CAPTHCA is not valid; ignore submission';
    }
}
// Need another else for first if here or keep it closed if you don't have an else