PHP和MySQL Cookie和Header不起作用

时间:2014-01-04 20:14:45

标签: php mysql connection

我遇到了问题,希望有人能够找到解决方案。 我只是更改了主机,网站不能完全运行。 基本上问题是某些代码不起作用。

检查if(!empty($db_password) and ($md5pass == $db_password))

的位置

回声有效,但其他事情没有,而且它不仅存在。我的其他文件也有类似的问题。

$username = $_POST['user'];
if(isset($username))
{
    $password = $_POST['password'];
    $md5pass = md5($password);

    $check_user = "SELECT ID,username,password FROM Members ";
    $check_user .= "WHERE username = '".$username."'";

    $checkuser_query = mysqli_query($dbconnection,$check_user);

    while($row = mysqli_fetch_array($checkuser_query,MYSQL_ASSOC))
    {
        $db_userid = $row['ID'];
        $db_username = $row['username'];
        $db_password = $row['password'];
        $db_avatar = $row['avatar'];
    }

    if(!empty($db_password) and ($md5pass == $db_password))
    {
        echo 'you are not awesome.';
        setcookie("LoginAuthorised","LoginAuthorised",time()+7200,"/");
        setcookie("id",$db_userid,time()+7200,"/");
        setcookie("username",$db_username,time()+7200,"/");
        header("Location: user.php?value=confirm");
    }else
    {
        echo '<div id="error">Password does not match</div>';
    }       
}
    echo '<p></p><p></p>
         <div id="lg_login_form">
            <form name="login_form" method="post">
                <div id="lg_login_title">Log In</div>
                    <div id="lg_login_form2">
                    <label>Username:</label>
                    <input type="text" name="user" id="username" value="" maxlength="20" />
                    <label>Password:</label>
                    <input type="password" name="password" value="" maxlength="20" />
                    <input name="submit_login" type="submit" value="Log In" id="lg_submit_log" />
                    <p></p>
                    <p></p>
                    <div id="lg_control_text">You have to login to access User Panel</div>
                </div>
            </form>
        <form name="register_redirect" action="user.php?value=register" method="post"  id="lg_register_redirect" >
            <label>If you want to login you have to register first. Registering takes only a few moments and it gives you multiple features.<br/></label>
            <input name="submit_registration" type="submit" value="Register" id="lg_submit_reg_log" />
            <p></p>
        </form>
    </div>';

1 个答案:

答案 0 :(得分:1)

您在调用setcookie()之前发送标头,这可能就是您遇到问题的原因。删除显示echo 'you are not awesome.';

的行