- 12
- Jul
There 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:
-
$referrer = $_SERVER[‘HTTP_REFERER’];
-
echo "Your referrer is correct.";
-
} else {
-
};
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.
Related Posts
Tags: HTTP Referrer, PHP, Web development


