繁体   English   中英

php标头位置重定向空白页

[英]php header location redirect blank page

我在标题位置上遇到问题,将我重定向到空白页,但没有看到代码,并且浏览器未报告任何错误。 我在当地与exapp合作

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(!headers_sent()){

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

现在我在benvenuto.php页面中还有一个问题,我有一个include('messagge.php'); 该目录始终位于views目录中,该目录与benvenuto.php相同。我发现自己始终与我不加载空白页,包括感谢您的帮助

您是否尝试更换:

header('Location:...');

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM