I would like to create a single URL that returns one image when loaded in a page within my domain, and another slightly modified image when loaded in a page outside my domain.
I am thinking along the lines of something like:
<?php
header('Content-type: image/jpg');
if (/**image is loaded within my domain**/)
{
readfile("image1.jpg");
}
else
{
readfile("image2.jpg");
}
?>
Is there something I can put in the if-statement to make it work? Possibly that works in all browsers?
Is there a way to do this without php?
You could use the referrer URL in the request and check to see if it is your domain. This is done using
$_SERVER['HTTP_REFERER'].However, the HTTP_REFERER URL can be easily modified by clients and can even sometimes not be set, so you need to be careful when using it.