コードに問題があります。ログインに問題がない場合、ページにリダイレクトされるはずです。ログインは成功していますが、ヘッダー転送でエラーが発生しています。問題が発生している行は次のとおりです。
header("Location: members.php");
エラー メッセージは次のとおりです: 警告: ヘッダー情報を変更できません - ヘッダーは既に送信されています
役立つ場合は、ページの完全なコードを次に示します。
<?php
// Connects to your Database
include("dbconnect.php");
mysql_select_db("maxgee_close2");
//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))
//if there is, it logs you in and directes you to the members page
{
$username = $_COOKIE['ID_my_site'];
$password = $_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 the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted
// makes sure they filled it in
if(!$_POST['username'] | !$_POST['password']) {
die('You did not fill in a required field.');
}
// checks it against the database
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['password'] = stripslashes($_POST['password']);
$info['password'] = stripslashes($info['password']);
$_POST['password'] = md5($_POST['password']);
//gives error if the password is wrong
if ($_POST['password'] != $info['password']) {
die('Incorrect password, please try again.');
}
else
{
// if login is ok then we add a cookie
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
//then redirect them to the members area and the line with the error
header("Location: members.php");
}
}
}
else
{
// if they are not logged in
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<h1>Login</h1>
Username:
<input type="text" name="username" maxlength="40">
Password:
<input type="password" name="password" maxlength="50">
<input type="submit" name="submit" value="Login">
</form>
<?php
}
include("topsite.php");
?>