Finding Out Where Users Have Come From In PHP

12th December 2008 - 1 minute read time

It is sometimes a good idea to find out where users can come from. When PHP is run the $_SERVER superglobal is always available and if the user has clicked on a link and landed on your page then the HTTP_REFERER value will be set. You can retrieve and view it on a test page like this.

  1. if ( isset($_SERVER[ HTTP_REFERER ]) ) {
  2. echo $_SERVER['HTTP_REFERER'];
  3. }

Of course you might want to do something useful with this. For example, you might want to know what link a user clicked on when they broke your application.

Add new comment

The content of this field is kept private and will not be shown publicly.