0

Now i need to get source page url when i navigate any page under specific domain i tried this jquery code

$(document).ready(function() {
var referrer =  document.referrer;
});

but i get the previous url page but i want to get the main link that open my domain for example i searched about my website from google then i open my website from google then i navigate any page under my domain ..... i want to get in any page that i come from google ..by the way my website is PHP.... can i make some thing like that ?!

  • have a look to this: http://stackoverflow.com/questions/1519349/track-where-users-come-from-in-php – marmeladze Oct 11 '15 at 13:42
  • The referer is the previous page, yes. You want a variable that remembers where you came from before you visited your site, no matter how many pages on your site you navigated to? – Mr Lister Oct 11 '15 at 13:44
  • Exactly @Mr Lister i mean that – user2303266 Oct 11 '15 at 13:49
  • Possible duplicate of [PHP: How to get referrer URL?](http://stackoverflow.com/questions/16374704/php-how-to-get-referrer-url) – Alex Oct 11 '15 at 13:58
  • But MR @Alex pages that i need to get source page url in them must be .html and my web site is https – user2303266 Oct 11 '15 at 14:03

1 Answers1

0

On the server side, you can use $_SERVER['HTTP_REFERER'] to get the referrer.

Now when the user links (or submits) from one page to the next in your website, but you still want the website they originally came from instead of the page they just were on, you should remember the original referrer in some way, for instance by storing it in a session variable. Something like this:

$ref = $_SERVER['HTTP_REFERER'];         // Get referrer
if (!$ref.strpos($_SERVER['HTTP_HOST'])) // It's not from the same domain?
  $_SESSION['originalreferrer'] = $ref;  // Nope, store in session

Then you will have $_SESSION['originalreferrer'] as the original referrer, as long as you include this code in each of your pages that may serve as a landing page from outside.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150