Sorry for poor title, not sure how to explain it in few words:
I have a php page which handles images to present them nicely and keep statistics on view count.
If a user accesses the image url directly in their browser (i.host.com/image.jpg), the image is displayed on a custom page. The location 'i.host.com/image.jpg' isn't the actual location of the image.
In code, the image url is checked in the db to get the actual url of it, and then I do a header redirect to that actual url. The location of the actual url isn't constant because a user can use websites (that allow hotlinking) as sources (for uploading their pictures etc and the 'fake' image name is a name they've defined for it).
I'm doing this by something like the following: (very basic example of what I have)
//Code for updating view count stats etc removed
if(/a/ is in the image url){
header("Location: $pathtoactualimage", true, 301);
} else {
//In my actual code, this echo produces an entire html page, not just image tag.
echo('<img src="http://i.host.com/a/image.jpg"/>');
//note that this image tag requests image using '/a/' path
}
A regular image tag without the use of that 'a' path doesn't display the image because the url is being processed as an actual page instead of an image.
I'm wondering whether it's possible to determine if an image url like i.host.com/image.jpg is accessed directly through browser, or if that image url is being called through some code somewhere (somewhere includes other websites) so that I don't have to use this messy 'a' path workaround?