PHP继续声明?

use*_*260 0 php redirect

我试图创建一个重定向,如果用户没有登录,我很困难

这是我正在使用的方法

<?php
if ( is_user_logged_in() ) {
?>

/*My Content*/

<?php
    } else {
        echo '<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.*****.com/non-member.php">';
    }
?>
Run Code Online (Sandbox Code Playgroud)

这工作正常,但它被延迟,并且能够在重定向之前看到页面几秒钟.

我想做的是这样的事情.

<?php
if ( is_user_logged_in() ) {
     /*IGNORE NEXT STATEMENT*/
} else {
        echo '<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.****.com/non-member.php">';
    }
?>
Run Code Online (Sandbox Code Playgroud)

我不确定这是否可能,但我会假设那里有一个方法.

cwa*_*ole 8

对于这种类型的行为,你最好使用标题:

<?php
// place at the top, before anything (including whitespace).
if( !is_user_logged_in() ) {
    header("Location: http://www.****.com/non-member.php");
    die(); // you don't want the rest of the page showing.
}
?>
Run Code Online (Sandbox Code Playgroud)

如果不让未登录的人首先看到该页面,那么这将是您正在尝试的.

  • @yi_H也许您应该阅读这个问题:http://stackoverflow.com/questions/1795025/what-are-the-differences-in-die-and-exit-in-php (4认同)