6

I want to get full referrer url in PHP. For instance, if I come to mywebsite from a google search, $_SERVER['REFERER'] gives me only www.google.com, but I want smth like www.google.com/search?q=KEYWORD

Google Analytics provides that for many search engines. I need to get "/search?q=KEYWORD" query string.

Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
halilenver
  • 1,465
  • 5
  • 13
  • 17
  • 5
    are you sure its $_SERVER['REFERER'] and not this => $_SERVER['HTTP_REFERER'] – GGio Feb 01 '13 at 20:45
  • 1
    Ahhh.. [Google](http://bytes.com/topic/php/answers/464557-how-get-referrer-parameters) – Kermit Feb 01 '13 at 20:47
  • 4
    /!\ Users using Google in HTTPS will not have any referrer. – Julien Palard Feb 01 '13 at 20:49
  • Duplicated? http://stackoverflow.com/questions/6768793/php-get-the-full-url – joaobarbosa Feb 01 '13 at 20:49
  • @JulienPalard google uses https on nearly most of there sites. – Class Feb 01 '13 at 20:50
  • @joaobarbosa: possibly not duplicated! –  Feb 01 '13 at 20:52
  • Why not testing your site from another domain (not google.com), just see if it prints full URL of the referrer, I tested on my PC, I can see full URL of the referrer –  Feb 01 '13 at 20:53
  • @Class That's why I warn halilenver, if he want to extract data from referrer, he will have some but not all expected (I actually use referrers as a source and we yet have a usable bunch of users from non-https google search) – Julien Palard Feb 01 '13 at 20:55
  • @JulienPalard is there anything that can be done to track google's query string when using https? – Lukas Lukac Sep 14 '15 at 17:49

1 Answers1

7

Put this in your script and have a look at it's content;

<pre>
<?php
var_dump($_SERVER);
?>
</pre>

This way you can find out which keys contain 'what'

thaJeztah
  • 27,738
  • 9
  • 73
  • 92