[英]PHP - Redirect only once
How can I make the header("Location: /path");
如何制作header("Location: /path");
to only redirect once? 只重定向一次?
Currenlty I have this: Currenlty我有这个:
//If account is locked by user.
if($userdata['account_locked'] == 1):
header("Location: /account/locked");
endif;
This script is checked in my header file. 该脚本在我的头文件中检查。 But it doesn't work, since it will just create a loop-redirect (infinit loop) 但这不起作用,因为它只会创建循环重定向(无限循环)
How can I do, so it only redirect once? 我该怎么办,因此只能重定向一次?
Thanks in advance. 提前致谢。
This is simple, but it's a bit ugly... 这很简单,但是有点丑陋...
//If account is locked by user.
if($userdata['account_locked'] == 1):
if ($_SERVER['REQUEST_URI'] != "/account/locked") header("Location: /account/locked");
endif;
You should use MVC, a controller should be aware of the loop. 您应该使用MVC,控制器应该知道循环。
EDITED It's better to use 编辑最好使用
$_SERVER['PHP_SELF']
instead of 代替
$_SERVER['REQUEST_URI'].
Edit: Changed from URL to URI. 编辑:从URL更改为URI。
if($userdata['account_locked'] == 1 && $_SERVER['HTTP_REFERER'] != 'http://'.$_SERVER['HTTP_HOST'].'/account/locked'):
header("Location: /account/locked");
endif;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.