Hackosis is an Open Blog. You Can Participate.

  • 12
  • Jul

PHPThere might be many cases where different output would want to be displayed differently depending on where someone is accessing a web page from.

A HTTP referer “identifies, from the point of view of an internet webpage or resource, the address of the webpage, of the resource which links to it”.

Below is a simple way to change the output of your web page based on HTTP referrer:

  1. $referrer = $_SERVER[‘HTTP_REFERER’];
  2. if (preg_match("/hackosis.com/",$referrer)) {
  3.       echo "Your referrer is correct.";
  4. } else {
  5.       header(‘Location: http://www.hackosis.com/’);
  6. };

What the above code will do is redirect anyone that doesn’t have a referrer that has ‘hackosis.com’ somewhere in the URL to your homepage. You could also state a message such as “Hotlinking images is not allowed”. In this case it would be appropriate to display the image in the first part of the if statement.

I hope you find this helpful and if you need any other tips on PHP code snippets, please let us know in the comments.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Related Posts


Tags: , ,

Like this post? Subscibe to the RSS feed.


Leave a Comment