Intelligent Back Button.


/ Published in: PHP
Save to your folder(s)

A back button that detects if the visitor came from your site initially. If they came from another URL it sends them to your index page instead.


Copy this code and paste it in your HTML
  1. <?php $mysite = "http://www.theUrlOfYourSite.com"; ?>
  2. <a href="<?php $url = parse_url($_SERVER['HTTP_REFERER']); /* detect referrer */
  3. if ($url['host'] == $_SERVER['HTTP_HOST']) { /* if domain matches, go back */
  4. echo $_SERVER['HTTP_REFERER']; } else { echo $mysite; } ?>"><!-- if from another domain, send them to my index page -->Back a page</a>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.