Laravel 4 如何检查一条路线是否仅来自/重定向自另一条路线?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23195987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4 how check if a route only comes/redirected from another route?
提问by user2002495
Say i have localhost/public/admin
that redirects immediately to localhost/public/user/login
.
假设我localhost/public/admin
立即重定向到localhost/public/user/login
.
How am I going to get the admin
value in user/login
?
我将如何获得admin
价值user/login
?
回答by afarazit
You'll need to grab the referer and check if it is contains 'admin'. Try the following
您需要获取引用并检查它是否包含“admin”。尝试以下
$referer = Request::referer();
// or
// $referer = Request::server('HTTP_REFERER');
if (strpos($referer,'admin') !== false) {
dd('coming from admin')
}
Edit #1: As pointed out by @tomvo you can also use URL::previous()
instead of Request::referer()
in L4
编辑 #1:正如@tomvo 所指出的,您也可以在 L4 中使用URL::previous()
而不是Request::referer()
Edit #2: It's actually mispelled as referer
instead of referrer
as point out by @JamesF
编辑#2:它实际上拼错了,referer
而不是@JamesFreferrer
指出的那样
Edit #3: In Laravel 5 the Request::referer()
method doesn't seem to exist anymore, you can still get it by using Request::header('referer')
as point out by @TheSerenin
编辑 #3:在 Laravel 5 中,该Request::referer()
方法似乎不再存在,您仍然可以通过使用Request::header('referer')
@TheSerenin 指出的方法来获取它