Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Result from $_SERVER['HTTP_REFERER'], when referer header is not sent to server

When the browser sends header info to the server, $_SERVER['HTTP_REFERER'] should give us the previous page URL right?

What returns from $_SERVER['HTTP_REFERER'], when header info is not sent to server? empty string? false? null? or... ?

like image 830
Oto Shavadze Avatar asked Dec 19 '12 08:12

Oto Shavadze


People also ask

Is Referer header always sent?

always: always send the header, even from HTTPS to HTTP.

What is $_ server [' Http_referer ']?

$_SERVER['HTTP_REFERER'] Returns the complete URL of the current page (not reliable because not all user-agents support it)

Why is Referer empty?

There might be several reasons why the referer URL would be blank. It will/may be empty when the enduser: entered the site URL in browser address bar itself. visited the site by a browser-maintained bookmark.

How do I get Referer headers?

To check the Referer in action go to Inspect Element -> Network check the request header for Referer like below. Referer header is highlighted. Supported Browsers: The browsers are compatible with HTTP header Referer are listed below: Google Chrome.


1 Answers

If the HTTP referer request header is not sent then the $_SERVER['HTTP_REFERER'] is probably not set, although it could be an empty string. Whether it is set or not in this case could depend on the server.

As with all HTTP request headers, check for its existence when reading:

$httpReferer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
like image 107
MrWhite Avatar answered Sep 27 '22 21:09

MrWhite