1

さて、キャプチャを設定しようとしていますが、このコードを入れると壊れます。

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["captcha"]))

72行目: if($_SESSION["captcha"]==$_POST["captcha"])

4

2 に答える 2

2

編集:

あなたが行方不明です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';
    }
}
于 2012-04-09T23:17:30.453 に答える
1
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
于 2012-04-09T23:21:28.740 に答える