星期一, 5月 14, 2007

限制網站使用者直接打開圖檔

如果用 PHP 對一個網站做密碼保護,使用者當然只能在輸入密碼後才能看到網頁內容,可是如果使用者在登入後記下圖片的網址,之後只要輸入這個網址,就能在不用密碼的情況下看到圖片。經試驗,以下的方法算是可以解決這個問題:

1. 打開 /etc/httpd/conf/httpd.conf
2. 如果原來是這樣:

Order allow, deny
Allow from all


就改成:

SetEnvIfNoCase Referer "^http://xxx\.xxx\.xxx\.xx" local_ref=1
<FilesMatch "\.(gif|jpg|png|tif|wmv|wma|swf)">
Order allow,deny
Allow from env=local_ref
Allow from xxx.xxx.xxx.xxx
Allow from 127.0.0.1
</FilesMatch>


這樣圖片只能在網頁裡顯示,直接輸入網址無法看到。

0 Comments:

張貼留言

<< Home