Laravel 5.4 get Referer

拟墨画扇 提交于 2019-12-01 15:33:59

It seems like this will do what you are looking for :

Request::server('HTTP_REFERER').

You can read the Api DOC here :

http://laravel.com/api/5.0/Illuminate/Http/Request.html#method_server

The reason you get Undefined index: HTTP_REFERER is because not all requests have a HTTP_REFERER header, only most of the requests that come from other websites. If you visit a website directly with the url, you wont be sending a HTTP_REFERER header.

So, you should check if the header is set first.

if (!isset($_SESSION["origURL"]) && array_key_exists('HTTP_REFERER', $_SERVER))
    $_SESSION["origURL"] = $_SERVER["HTTP_REFERER"];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!