2011-08-14 187 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."; 
     } 
    } 
?> 
相关问题