[英]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.