Reputation: 595
I have a query. Is there a way to detect whether the website is accessed directly or in-directly? Let me make my question more clear to you with an example.
Let's say I have an Image sharing website. When an user opens the website and views an image, it adds to the total impressions of the image. But I have seen people embedding DIRECT image Url in the forums instead of thumbnail code so as to increase impressions. This is supposed to be an indirect access to the website which I want to prevent.
I simply want a solution that allows the website to be viewed only directly and not via false embedding of URL in forums, or via iFrames, or etc.
Is there a solution for this in PHP?
Upvotes: 0
Views: 280
Reputation: 783
You need to prevent Hotlinking of your images. I quote
Hotlinking is a term used on the Internet that refers to the practice of displaying an image on a website by linking to the same image on another website
Add the following to your .htaccess
file and change the domain as required.
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
Upvotes: 2
Reputation: 17720
Inspect the HTTP referer
header. While this can be spoofed, it's the easiest way to go.
http://en.wikipedia.org/wiki/HTTP_referer
Upvotes: 0