Posted By

tomdebruin on 06/16/08



Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Intelligent Back Button.

 / Published in: PHP

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.

  1. <?php $mysite = ""; ?>
  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  

You need to login to post a comment.