[英]How to Prevent Direct URL Access?
請幫我解決盜鏈問題,如何防止直接訪問此 URL 並將訪問者重定向到 index.php:
http://www.example.com/index.php?link=http://www.anysite.com/dir/file&name=on&email=on&submit=on
你在尋找這樣的東西:
if(!strpos('mysite.com',$_SERVER["HTTP_REFERER"])) header('Location: index.php')
為了回答這個問題,我假設您不在乎同一個用戶是否多次訪問它(假設第一次訪問是通過主索引頁面進行的)。 這也假設用戶將接受 cookies。
在主索引頁面上時:
加載 url 時:
使用 htaccess 文件是解決此問題的常見方法:
來自http://altlab.com/htaccess_tutorial.html
此代碼特別重定向任何試圖熱鏈接圖像的人。
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://img148.imageshack.us/img148/237/hotlinkp.gif [L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.