2011-08-14 94 views
-1

我有這段代碼處理用戶,然後將它們重定向到用戶主頁。解析錯誤:語法錯誤:意外'{'

<?php 
    $username = $_POST['username']; 
    $password = $_POST['pwd']; 

    $file = file_get_contents("userdb.html"); 
    if(!strpos($file, $username)) { 
     echo "Your username was not found in our database. Please go back and try again."; 
    } else { 
     echo "Redirecting..."; 
     if (md5($password) == !strpos($file, (md5($password))) { 
      echo "Redirecting..." 
      header ('Location: ./userhome.php') 
     } else { 
      print "Whoops! Your password seems to be incorrect. Go back and try again." 
     } 
    } 
?> 

而我得到的錯誤:

Parse error: syntax error, unexpected '{' in userprocess.php on line 11 

有人能告訴我這個問題好嗎?我認爲這可能是if語句裏面的內容,但是我能爲替代方法做些什麼?謝謝。

+1

嘗試使用良好的IDE,你會看到標記的語法錯誤。 NetBeans或PhpStorm。 –

+2

你很快就會回來問,爲什麼重定向不起作用? –

+0

你真的在HTML文件中保存用戶名和密碼嗎?即使你散列和鹽,你仍然不應該把它們交出來。 – Marcel

回答

4

首先,此行缺少一個右括號:

if (md5($password) == !strpos($file, (md5($password))) { 

計算的數量爲() - 它們需要匹配。

當你解決這個問題時,你仍然會得到錯誤,因爲PHP語句需要以分號結尾。

以下行的所有缺少的分號:

echo "Redirecting..." 
header ('Location: ./userhome.php') 
print "Whoops! Your password seems to be incorrect. Go back and try again." 

您需要修改它們,你就可以不通過語法錯誤,運行該程序的所有了。

希望有所幫助。

+0

在我發佈這個之後,我意識到分號(對我來說是一個非常愚蠢的問題),但是感謝你修改if語句。這是一個清晰的答案。謝謝。 – snarkyt123

+0

此外,'echo'後跟'header'和'print'太明顯了,忽略了一個錯誤... –

+0

@Linus - 的確 - 但我已經在原始問題的範圍之外了,指出分號。 :) – Spudley

1

變化

if (md5($password) == !strpos($file, (md5($password))) 

if (md5($password) == !strpos($file, md5($password))) 
1

你缺少的行右括號:

if (md5($password) == !strpos($file, (md5($password))) { 
1
<?php 
    $username = $_POST['username']; 
    $password = $_POST['pwd']; 

    $file = file_get_contents("userdb.html"); 
    if(!strpos($file, $username)) { 
     echo "Your username was not found in our database. Please go back and try again."; 
    } else { 
     echo "Redirecting..."; 
     if (md5($password) == !strpos($file, md5($password))) { 
      echo "Redirecting..."; 
      header ('Location: ./userhome.php'); 
     } else { 
      print "Whoops! Your password seems to be incorrect. Go back and try again."; 
     } 
    } 
?> 
相關問題