I'm trying to get the Referer of my users. Like if they come from facebook, youtube, google or anything else.
Now I've tried something like that:
$referrer = $this->request->headers->get('referer');
$url = $referrer ? $this->to($referrer) : $this->getPreviousUrlFromSession();
return $url ?: $this->to('/'); // returns: Method referer does not exist.
This:
return $_SERVER["HTTP_REFERER"] // returns Undefined index: HTTP_REFERER
that:
session_start();
if ( !isset( $_SESSION["origURL"] ) ) {
$_SESSION["origURL"] = $_SERVER["HTTP_REFERER"]; // returns Undefined index: HTTP_REFERER
}
But nothing worked like expected.
Does someone know a solution how I can check the referer?
I need that because I want to check if the user comes from some specific URL's and if so, I want to give the user some extra "clicks" to rank up. Something like a small affiliate system.
$referrer = $this->request->headers->get('referer'); $url = $referrer ? $this->to($referrer) : $this->getPreviousUrlFromSession(); return $url ?: $this->to('/'); // returns: Method referer does not exist.
It's available in the HTTP referer header. You can get it in a servlet as follows: String referrer = request. getHeader("referer"); // Yes, with the legendary misspelling.
$_SERVER['HTTP_REFERER'] will give you the referrer page's URL if there exists any. If users use a bookmark or directly visit your site by manually typing in the URL, http_referer will be empty. Also if the users are posting to your page programatically (CURL) then they're not obliged to set the http_referer as well.
$_SERVER['HTTP_REFERER'] Returns the complete URL of the current page (not reliable because not all user-agents support it)
It seems like this will do what you are looking for :
Request::server('HTTP_REFERER').
You can read the Api DOC here :
https://laravel.com/api/8.x/Illuminate/Http/Request.html#method_server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With