好的,这是一个简单的问题,也是一个愚蠢的问题,但由于我一直在 localhost 上进行开发,我什至没有意识到这是一个问题。登录脚本中重定向到成员页面的标题不起作用,因为它的位置不正确。这在 wamp 上没有引起问题,但在实时服务器上。该脚本包含在一个 html 文件中,原因太长,无法在此处说明。脚本中没有任何内容,直到出现问题,然后脚本停止。我应该把重定向标头放在哪里?
这是登录脚本:
<?php
// Connects to your Database
include ("database.php");
//Checks if there is a login cookie
if(isset($_SESSION['username']))
//if there is, it logs you in and directes you to the members page
{
echo '<div id="probwarn"><t1><b>You are already logged in! You do not need to do it again.</b></t1></div>';
}
//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted
$flag = 0; // Safety net, if this gets to 1 at any point in the process, we don't upload.
// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
echo('<div id="probwarn"><t1>You did not fill in a required field.</t1></div>');
$flag = $flag + 1;
}
// checks it against the database
$pass = htmlspecialchars(mysql_real_escape_string($_POST['pass']));
$username = htmlspecialchars(mysql_real_escape_string($_POST['username']));
$check = mysql_query("SELECT * FROM members WHERE username = '".$username."'")or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
if($flag == 0) {
echo('<div id="probwarn"><t1>You must <a href="register.html"> <b>register</b></a> first.</t1></div>') ;
}
$flag = $flag + 1;
}
$check = mysql_query("SELECT * FROM members WHERE username = '".$username."'")or die(mysql_error());
$pass = htmlspecialchars(mysql_real_escape_string($_POST['pass']));
$username = htmlspecialchars(mysql_real_escape_string($_POST['username']));
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
if($flag == 0) {
echo('<div id="probwarn"><t1>Incorrect password, please try again.</t1> </div>');
$flag ++;
} }
}
// if login is ok then we add a cookie
if($flag == 0) {
$pass = htmlspecialchars(mysql_real_escape_string($_POST['pass']));
$username = htmlspecialchars(mysql_real_escape_string($_POST['username']));
$_SESSION['username']=$username;
$_SESSION['password']=$pass;
//then redirect them to the members area
//THIS IS THE HEADER
header("Location: ../members.html");
}
}
else
// if they are not logged in
?>
LOGIN FORM IS USUALLY HERE