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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:23:47  来源:igfitidea点击:

Laravel 4 how check if a route only comes/redirected from another route?

laravellaravel-4laravel-routing

提问by user2002495

Say i have localhost/public/adminthat redirects immediately to localhost/public/user/login.

假设我localhost/public/admin立即重定向到localhost/public/user/login.

How am I going to get the adminvalue 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 refererinstead of referreras 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 指出的方法来获取它