php头位置重定向空白页


php header location redirect blank page

我有一个标题位置问题,在不让我看到代码的情况下将我重定向到一个空白页面,浏览器也不会报告任何错误。我在本地使用示例

class UserController
{
    public $username = '';
    private $logged   = false;
    private $usermodel = '';
    public function __construct()
    {   session_start();
        $this->usermodel = new UserModel();

        if ($_SERVER['REQUEST_METHOD']=='POST' && isset($_GET['action'])&& $_GET['action']== 'login' ){
            $username = (isset($_POST['username']))? $_POST['username'] :false ;
            $password = (isset($_POST['password']))? $_POST['password'] :false ;
            if ($username !=false && $password !=false && $this->usermodel->checkLogin($username, $password)){
                $this->username =$username ;
                $this->logged = true ;
                $_SESSION['username']= $username ;
                $_SESSION['logged']= true ;
                $_SESSION[ 'message' ]  = 'Login effettuato correttamente';
            }else{
                $_SESSION[ 'message' ]  = 'Errore con il login; riprovare!';
            }
        }
        elseif (isset($_GET['action'])&& $_GET['action']== 'logout'){
            unset($_SESSION['username']);
            unset($_SESSION['logged']);
            $_SESSION[ 'message' ] = 'Logout effettuato correttamente';
        }
        elseif (isset($_SESSION['username'])&& isset($_SESSION['logged'])){
            $this->username = $_SESSION['username'] ;
            $this->logged = true ;
        }
        elseif(($_SERVER['REQUEST_METHOD']=='POST' && isset($_GET['action'])&& $_GET['action']== 'registra' )){
            $username = (isset($_POST['username']))? $_POST['username'] :false ;
            $password = (isset($_POST['password']))? $_POST['password'] :false ;
            $repassword = (isset($_POST['repassword']))? $_POST['repassword'] :false ;
            $nome_reale = (isset($_POST['nome_reale']))? $_POST['nome_reale'] :false ;
            $email = (isset($_POST['email']))? $_POST['email'] :false ;

            if ($username !=false && $password !=false && $repassword !=false && $nome_reale && $email !=false
               && $this->usermodel->Registration($username,$password,$repassword,$nome_reale,$email) )
            {
                $this->username =$username ;
                $this->logged = true ;

                $_SESSION['username']= $username ;
                $_SESSION['logged']= true ;
                $_SESSION[ 'message' ]  = "registrazione effettuato correttamente benvenuto $username";
            }
        }
        $this->redirectToProperArea();
    }
    public function logged(){
        return $this->logged ;
    }
    public function redirectToProperArea(){
        $script_file = basename( $_SERVER[ 'SCRIPT_NAME' ] );
        if ( $this->logged() && $script_file == 'login.php' ) {
            ob_end_clean();
            header('Location: ../index.php' );
            exit;
        } 
        elseif ( !$this->Logged() && ( $script_file == 'index.php' && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] != 'index' && $_GET[ 'action' ] != 'detail' && $_GET[ 'action' ] != 'logout' ) ) {
            ob_end_clean();
            header('Location: ../login.php');
            exit;
        }
        elseif ( $this->logged() && $script_file == 'registra.php' ) {
            ob_end_clean();
            header('Location: views/benvenuto.php');
            exit;
        }
    }
}

我使用函数求解`if(!header_sent()){

          header('Location:views/benvenuto.php');
          exit;
        }  `

现在我在benvenuto.php页面中遇到了另一个问题,我有一个include('message.php');它总是在视图目录中,与benvenuto.php相同。我发现自己总是和我在一起,不加载空白页包括感谢您的帮助

您是否尝试过替换:

header('Location:...');

echo '<script>document.location="..."</script>';