简体   繁体   中英

How do I detect the site a user has navigated from?

I'm developing a simple website using PHP , HTML and JS , and I'd like to have the page footer change based on what site the user came from. For example:

if user is from google.com
  use footer-1.php
if user is from qwerty.com
  use footer-2.php

Is there a way to detect the site a user has navigated from?

Update (here is the solution I use, pasting JS into footer.php):

sessionStorage.setItem("referent", document.referrer);
          
if (sessionStorage.referent.search('google') >= 0) {
    console.log("Your message");
    //Your code

}

I don't think it is possible to check if the user is coming from google.com or anyotherdomain.com unless there is additional information in the query string.

Like

https://www.anydomain.com?source=google

Now, Search Engine like Google.com doesn't really add Query string like this. So it's not possible to find out the source of the request.

I hope that helps. Thanks.

Sorry for the slow reply but I checked the solution in vanilla JS where javascipt get document. referrer and ten with if/else statments change footer acoording to my needs. But the problem continues when the user starts moving inside the web page, and the footer changes again but not according to my needs

See $_SERVER['HTTP_REFERER']

$previous_page = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM