We have some static images, publicly available. However, we want to be able to redirect that images if not used in image tag, ex:
http://server.com/img/my_cool_image.jpg
i want to if some one open it directly with that link it will be redirect to the home page
http://server.com
but if that were used in image(src) tag it will opened normaly
<img src="http://server.com/img/my_cool_image.jpg">
is threre any way to do something like that? Thanks.
You need to check HTTP_REFERER. If refer is set that means it is not direct access using manual input in browser address bar. HTTP_REFERER is the way to know where the comes from (previous page/site, etc)
if(!isset($_SERVER['HTTP_REFERER'])) {
redirect('http://server.com');
}