PHP: How to get referrer URL?

I have a page (index.php) where customers can send me emails. Now I want to see from what website that visitor is coming from.

How can I get the Referrer URL with PHP? I tried with $_SERVER['HTTP_REFERER'] but it's empty all the time. What variable do I need to consider?

Here is what my $_SERVER contains; I put some ---- CENSORED ---- for privacy concerns, there are actually real values.

array(31) {
  string(33) "/home/anything/public_html/design"
  string(7) "CGI/1.1"
  string(129) "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1"
  string(13) "gzip, deflate"
  string(14) "en-US,en;q=0.9"
  string(8) "no-cache"
  string(10) "Keep-Alive"
  string(189) "__utma=76630272.1468291432.1367655794.1367669576.1367674157.3; __utmb=76630272.1.10.1367674157; __utmc=76630272; __utmz=76630272.1367655794.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"
  string(25) " ---- CENSORED ---- "
  string(57) "Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Version/12.15"
  string(13) "/bin:/usr/bin"
  string(0) ""
  string(3) "200"
  string(10) ""
  string(5) "57897"
  string(3) "GET"
  string(12) "/referer.php"
  string(45) "/home/anything/public_html/design/referer.php"
  string(12) "/referer.php"
  string(13) " ---- CENSORED ---- "
  string(35) " ---- CENSORED ---- "
  string(25) " ---- CENSORED ---- "
  string(2) "80"
  string(8) "HTTP/1.1"
  string(189) "
Apache/2.2.19 (Unix) mod_ssl/2.2.19 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/ Server at ---- CENSORED ---- Port 80

  string(125) "Apache/2.2.19 (Unix) mod_ssl/2.2.19 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/"
  string(24) "UYUNcUPeiDsAABkR2eYAAAAj"
  string(12) "/referer.php"
  array(0) {

$_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. You're missing all _, is that a typo?


Underscore. Not space.



If $_SERVER['HTTP_REFERER'] variable doesn't seems to work, then you can either use Google Analytics or AddThis Analytics.


But if you run a file (that contains the above code) by directly hitting the URL in the browser then you get the following error.

Notice: Undefined index: HTTP_REFERER

Previous : RecylerView onClickListener works on all fragment
Next : how can exclude id with having multiple value?