开发者

If file is not called "somename.php" then redirect

I have a php file that is included in every other page, that's why I want to modify the code so it's not going to 开发者_如何学编程loop forever.

Basically I want to redirect from any other page if the user is not a member to a splash page, the error comes when we reach splash.php and it executes the same redirect again and again (infinite loop).

So I want to modify the code to execute only if the current page is NOT splash.php

Thanks

if (!isMember()) {
    header('Location: ' . MY_URL_ROOT . 'splash.php');
}


The following should suffice:

if (!isMember() && $_SERVER['PHP_SELF'] != MY_URL_ROOT . 'splash.php') {
    header('Location: ' . MY_URL_ROOT . 'splash.php');
    exit();
}

Incidentally, you should always call exit after you use a header to re-direct, unless you specifically want the server to continue processing the rest of the script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜