2014-10-06 16 views
-6

我已經爲我的登錄頁面編寫了此代碼.. !!問題是這是它給我的代碼的最後一行89語法錯誤意外的$結束。我嘗試了所有可用的解決方案,但沒有發生任何事變量和查詢都很好,我已經徹底檢查過了。附:我使用notepad ++ IDE,所以語法錯誤是最小的(*括號打開關閉)。提前致謝。!!!!

<?php session_start(); 
if(isset($_COOKIE["usNick"]) && isset($_COOKIE["usPass"])){ ?> 
    <META HTTP-EQUIV="REFRESH" CONTENT="0;URL=myaccount.php"> 
<?php 
    exit(); 
} 

$display_error = ""; 
$username = ""; 

if ($_POST['username']) { 
    $username = $_POST['username']; 
    if(strtolower($_POST['code'])!= strtolower($_SESSION['texto'])){ 
     $display_error = "* Security Code Error"; // error language 
     include ('error.php'); 
     exit(); 
    }else{ 
     include('includes/config.inc.php'); 
     $username=uc($_POST['username']); 
     $pass=uc($_POST['password']); 
     $password = sha1($pass); 

     if ($password==NULL) { 
      $display_error = "* All fields are required"; // error language 
      include ('error.php'); 
      exit(); 
     }else{ 
      $myDb->connect(); 
       $query = mysql_query("SELECT username,password FROM yob_users WHERE username = '$username'") or die(mysql_error()); 
       $data = mysql_fetch_array($query); 
      $myDb->close(); 
      if($data['password'] != $password) { 
       $display_error = "* Please, Check your username/password."; // error language 
       include ('error.php'); 
       exit(); 
      }else{ 
       $myDb->connect(); 
        $query = mysql_query("SELECT username,password FROM yob_users WHERE username = '$username'") or die(mysql_error()); 
        $row = mysql_fetch_array($query); 
       $myDb->close(); 
       $nicke=$row['username']; 
       $passe=$row['password']; 
       setcookie("usNick",$nicke,time()+7776000); 
       setcookie("usPass",$passe,time()+7776000); 
       $lastlogdate = date("F j, Y - g:i a"); 
       $lastip = getRealIP(); 
       $myDb->connect(); 
        $querybt = "UPDATE yob_users SET lastlogdate='$lastlogdate', lastiplog='$lastip' WHERE username='$nicke'"; 
        mysql_query($querybt) or die(mysql_error()); 
       $myDb->close(); ?> 
       <META HTTP-EQUIV="REFRESH" CONTENT="0;URL=myaccount.php"> 
<? 
      } 
     } 
    } 
}else{ 
    include ('header.php'); 
?> 
     <div id="content"> 
      <p class="error"><?php echo $display_error;?></p> 

      <form action="login.php" method="post" class="f-wrap-1"> 
      <div class="req"><a href="signup.php">Not Registered?</a><br /><a href="recoverpass.php">Forgot your Password?</a></div> 
      <fieldset> 

      <h3>Member Login</h3> 

      <label for="firstname"><b>Username:</b> 
      <input id="username" name="username" type="text" class="f-name" autocomplete="off" tabindex="1" /><br /> 
      </label> 
      <label for="password"><b>Password:</b> 
      <input id="password" name="password" type="password" class="f-name" autocomplete="off" tabindex="2" /><br /> 
      </label> 
      <label for="code"><b>Security Code:</b> 
      <input id="code" name="code" type="text" class="f-name" autocomplete="off" tabindex="3" /><br /> 
      </label> 
      <label for="code2"><b>&nbsp;</b> 
      <img src="image.php?<?php echo $res; ?>" /><br /> 
      </label> 
      <div class="f-submit-wrap"> 
      <input type="submit" value="Submit" class="f-submit" tabindex="4" /><br /> 
      </div> 
      </fieldset> 
      </form> 
     </div> 
<?php 
include ('footer.php'); 
} 
?> 
+4

確保你有所有的右括號。你幾乎肯定不會。 – 2014-10-06 19:37:14

+2

請[不要使用'mysql_ *'函數](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 *他們不再維護,並[已正式棄用](https://wiki.php.net/rfc/mysql_deprecation)*。學習[準備的語句](http://en.wikipedia.org/wiki/Prepared_statement),並使用[PDO](http://us1.php.net/pdo)或[MySQLi](http:// us1.php.net/mysqli)。 [本文](http://php.net/manual/en/mysqlinfo.api.choosing.php)將幫助你決定。 – 2014-10-06 19:37:17

+0

這就是爲什麼嵌套太深被稱爲不好的做法。 – DanFromGermany 2014-10-06 19:38:13

回答

2

您在您發佈的代碼的第52行有<?標記。

這是短標籤語法。沒有short open tags set/on,會導致該錯誤。

所以將它改爲<?php,你應該很好走。


  • 見識

如果您稍後決定使用<?=
這也是短的標記語法這相當於在PHP <?php echo

同樣,如果沒有設置短標籤,那將需要<?php echo,。

如果還有其他<?標籤,請全部更改爲<?php


要如何啓用短標籤讀了,參觀這個問答& A於堆棧:


腳註:

確保您包含的文件不包含短標籤。

+0

我已將您的解決方案應用於login.php文件頭和頁腳文件不包含任何此短代碼..但沒有發生錯誤仍然存​​在..您可以運行此代碼,而不包括頁眉和頁腳。 PLZ其緊急..! – 2014-10-07 10:06:31

相關問題