NiftyHost Forums (Archive)
A website question - Printable Version

+- NiftyHost Forums (Archive) (https://niftyhost.chary.us/support)
+-- Forum: Technology (https://niftyhost.chary.us/support/forum-7.html)
+--- Forum: Coding (https://niftyhost.chary.us/support/forum-12.html)
+--- Thread: A website question (/thread-456.html)

Pages: 1 2


A website question - 903 - 08-01-2010

If I put some pictures on my website in this server.How can I do with PHP to make these pictures display normally on my page but display nothing or display a warning picture on other website?


RE: A website question - Matt - 08-01-2010

I believe what you're looking for is "HotLink Protection". It can be found at your cPanel, it's called "HotLink Protection". Turn it on, and make sure it protects your domains.


RE: A website question - RichardGv - 08-01-2010

Hotlink protection does not actually need PHP to work. The most common technique is to judge whether the user is accessing from a correct source by checking the "Referrer" HTTP header. This can be achieved easily by Apache itself:
Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\\.)?yoursite\\.com [NC]
RewriteRule \\.(gif|jpe?g)$ /images/hotlink.$1 [L]
(These code are supposed to be added to .htaccess or httpd.conf. The respective hotlink error images need to put on your server. The code came from this article: http://www.dagondesign.com/articles/hotlink-protection-with-htaccess/ )
Of course, using cPanel hotlink protection is easier, if less customizable. (And I believe cPanel actually do it by writing a .htaccess.)


RE: A website question - 903 - 08-01-2010

I think it works.But I can't change this server's httpd.conf.


RE: A website question - RichardGv - 08-01-2010

(08-01-2010, 01:27 PM)903 Wrote: I think it works.But I can't change this server's httpd.conf.

Well, you can almost never change the httpd.conf of the server of a shared hosting, and you should not, either. Just add them to .htaccess . (But make sure you have read the notes below the code.) .htaccess does have some significant differences and limitations in comparison to httpd.conf, but they have the same syntax, and when doing some simple jobs, they are essentially the same.


RE: A website question - 903 - 08-01-2010

thanks,I wonder where is the .htaccess.


RE: A website question - HiddenKnowledge - 08-01-2010

If it's not in the directory then you need to make the file .htaccess yourself.


RE: A website question - 903 - 08-01-2010

Thanks.Then which folder should I creat the file?The root folder or every folder I want to protect?


RE: A website question - Zach - 08-01-2010

The lowest-level to protect. If I had /bob/joe/jane.png and /bob/doug/jeff.png and wanted to protect both, i'd put the .htacess in /bob/.htaccess. If I wanted /curly/hair/clown.png to be protected as well, put it in /.htaccess.


RE: A website question - Matt - 08-01-2010

Guess my way was outnumbered :P People like .htaccess more, I suppose.