我有一个登录,注册页面。注册页面工作正常,但我的登录页面有问题。当我成功登录时,它应该将我重定向到一个名为 members.php 的页面,但它只是停留在同一个页面上,并且不去任何地方。这是我认为可能出现问题的 login.php 页面的代码:
<?php
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
if (isset($_COOKIE['ID_my_site'])) {
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());
while ($info = mysql_fetch_array($check)) {
if ($pass != $info['password']) {
} else {
header("Location: members.php");
}
}
}
if (isset($_POST['submit'])) { // if form has been submitted
if (!$_POST['username'] | !$_POST['pass']) {
die('<h1 class="error"></h1><p>You missed something</p>');
}
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM users WHERE username = '" . $_POST['username'] . "'") or die(mysql_error());
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('<h1 class="error"></h1><p>That user does not exist in our database</p>');
}
while ($info = mysql_fetch_array($check)) {
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
if ($_POST['pass'] != $info['password']) {
die('<h1 class="error"></h1><p>Incorrect password, please try again</p>');
} else {
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
header("Location: members.php");
}
}
} else {
?>
<h1 class="login"></h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Username</p><input type="text" class="username" name="username">
<p>Password</p><input type="password" class="password" name="pass">
<div><button type="submit" name="submit" value="Login">Log in</button></div>
</form>
<?php
}
?>