PHP页面加载错误


PHP page load error

我试图使用PHP隐藏页面的内容,但总是收到错误这是我正在使用的代码。$pass的数据来自另一页提交的表格:

<?php
 $pass = $_POST['pass'];
 $password = "content";  // Modify Password to suit for access, Max 10 Char.
?>
<html>
<title></title>
<head>
<?php 
 // If password is valid let the user get access
 if ( "$pass" == "$password") {
?>
<!-- START OF HIDDEN HTML - PLACE YOUR CONTENT HERE -->
</head>
<body>
You have gained access!
<!-- END OF HIDDEN HTML -->
<?php 
 } else {
   // Wrong password or no password entered display this message
   print "<p align='"center'"><font color='"red'"><b>Restricted Area!</b><br>Please enter from the log in page</font></p>";}
}
?>
</body>
</html>
print "<p align='"center'"><font color='"red'"><b>Restricted Area!</b><br>Please enter from the log in page</font></p>";}

在这行中,在末尾有一个额外的大括号。所以在你的文件中,你有一个额外的大括号。尝试将此行更改为

print "<p align='"center'"><font color='"red'"><b>Restricted Area!</b><br>Please enter from the log in page</font></p>";

它应该起作用。

Link,您的代码没有运行,最终出现了一个致命错误,只是因为在print之后有一个额外的},这意味着您的else以一个过多的}结束。删除它,然后你的代码将运行没有任何错误:

在线工作示例

此外,如果你比较变量,你不能使用引号",试着这样做:

if ( $pass == $password) {