取消输出缓冲

时间:2013-01-23 07:41:59

标签: php .htaccess output-buffering login-script

我的登录脚本是这样的,通常包括在内 在登录表单上:

<?php
if(isset($_POST['login']))
{
    require_once("dbconfig.php");
    $email=$_POST["username"];
    $password=$_POST["password"];
    $password=md5("$pass");
    $msg="";
    if ($email==""){
        $msg=$msg."You didn't enter your Username.<br/>";
        $fstatus= "NOTOK";}
        if ($pass==""){
            $msg=$msg."You didn't enter your Password.";
            $fstatus= "NOTOK";}
            if($fstatus=="NOTOK"){ 
                echo "<div class=error>$msg</div>";
            }
            else{
                $logincheck=mysql_query("SELECT id FROM users WHERE username='$email' AND password='$password' limit 1");
                if(mysql_num_rows($logincheck)==0)
                {
                    echo "<div class=error>Invalid login: wrong username or password.</div>";
                }
                else
                {
                    $_SESSION['XYZ']= TRUE;
                    header("Location:member-page.php");
                }
            }
        }
    }
}
?>

要使重定向起作用,我通常会在指令中使用htaccess文件 PHP_FLAG output_buffering on。但这在某些服务器上不起作用。我明白 可以取消htaccess文件,如何重新编写登录脚本 使重定向工作。

1 个答案:

答案 0 :(得分:1)

你可以放......

<?php
    ob_start();

作为文件中的第一件事(并确保PHP代码之前没有其他内容)。这将turn on output buffering而不需要.htaccess文件。

相关问题