0

I want to create a go back button on a single.php in WordPress. I know I can easily do that with window.history.go(-1) but in the case of the visitor come from another site, I want to redirect to the homepage of my site.

In other words: How can I know if the previous page is an internal link to my site? And if not, redirect to the homepage?

brasofilo
  • 25,496
  • 15
  • 91
  • 179
Zorkzyd
  • 929
  • 3
  • 12
  • 30
  • 2
    You could look into `if(isset($_SERVER['HTTP_REFERER']))` and check if your domain matches it, and then use header to redirect them accordingly – Stender Apr 17 '18 at 09:30
  • but it can be spoofed, and is not always set - basically it is up the the browser that your user is using. – Stender Apr 17 '18 at 09:31
  • 2
    check this answer, to see when referer will be empty : https://stackoverflow.com/questions/6880659/in-what-cases-will-http-referer-be-empty – Stender Apr 17 '18 at 09:33

0 Answers0