PHP代码不起作用 - 导致错误500

Lia*_*m W -2 php

这是不起作用的代码,当我尝试在浏览器中查看此页面(chrome)时,我收到500内部错误.有人可以帮忙吗?

<?php
$user = $_POST["user"];
$pass = $_POST["pass"];
$name = someuser;
$passw = somepassword;
if (!isset($_POST['login_button'])) {

} else {
if (&user == $name) {
      if ($pass == $passw) {
          setcookie('liamblogprox', 'hi', );
          header.location('http://liamwli.co.uk/proxy/proxy.php');
      } else {
      echo "Invalid User or Pass!"; }

}else {
echo "Invalid User or Pass!"; }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <link rel="stylesheet" type="text/css" href="style2.css" media="screen,projection" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="generator" content="GiffHost - http://www.giffhost.co.uk/" />
    <title>Private Proxy</title>
<style type="text/css">
#container #content center table tr td center h1 i b {
    color: #000;
}
</style>
</head>
<body>

    <div id="container">

      <div id="header">
        <h1>Private Proxy</h1>
            This is a paid super fast Proxy</div>

        <div id="subheader">
          <ul id="navigation">
                <li><a href="index.html">About</a></li>
                <li><a href="register.html">Register</a></li>
                <li class="active"><a href="login.html">Log In</a></li>
                <li><a href="contact.html">Contact</a></li>
          </ul>

      </div>

      <div id="content">

<center>
<table bgcolor="white" cellpadding="12" border="1">
<tr><td colspan="2" bgcolor="#FFFFFF"><center>
  <h1><i><b>Log In</b></i></h1></center></td></tr>
<tr><td><h1><i><b>UserName:</b></i></h1></td><td><form name="login" action="<?php echo $PHP_SELF;?>" method="post"><input
name="user" type="text"></td></tr>
<tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass"
type="password"></td></tr>
<tr><td><center><input type="submit" value="Login"
name="login_button"></center></td><td><center><br><input
type="Reset"></form></td></tr></table></center> 
      </div>
        <div id="footer">

      Designed by<a href="http://www.giffhost.co.uk"> GiffHost </a></div>

    </div>

</body>
</html> 
Run Code Online (Sandbox Code Playgroud)

Whi*_*ant 6

这里有很多不妥之处.

<?php
// Are these actual login credentials? They should be quoted anyway.
$name = "alex";
$passw = "liamgoogle4530";

// This is a better way of checking to see if the form has been posted
if ($_SERVER['REQUEST_METHOD'] == 'POST') 
{
    // The post variables are only likely to exist if the form has been submitted
    $user = $_POST["user"];
    $pass = $_POST["pass"];

    // $ sign, not & for $user variable, why not combine the check into one?
    if ($user == $name && $pass == $passw) 
    {
        // You need to set an expiry on the cookie, I've set it to one hour
        setcookie('liamblogprox', 'hi', time()+3600);
        // This is how you do redirects in PHP
        header('Location: http://liamwli.co.uk/proxy/proxy.php');
    }
    else 
    {
        echo "Invalid User or Pass!"; 
    }
}
?>
Run Code Online (Sandbox Code Playgroud)