[英]How to Prevent Direct URL Access?
Please help me to resolve hotlinking, how to prevent direct access to this URL and redirect visitors to index.php:请帮我解决盗链问题,如何防止直接访问此 URL 并将访问者重定向到 index.php:
http://www.example.com/index.php?link=http://www.anysite.com/dir/file&name=on&email=on&submit=on
are you searching for something like this:你在寻找这样的东西:
if(!strpos('mysite.com',$_SERVER["HTTP_REFERER"])) header('Location: index.php')
For purposes of answering this, I'm going to assume you don't care if the same user accesses it multiple times (provided that the first visit came through the main index page).为了回答这个问题,我假设您不在乎同一个用户是否多次访问它(假设第一次访问是通过主索引页面进行的)。 This also assumes the user will accept a cookies.
这也假设用户将接受 cookies。
When on the main index page:在主索引页面上时:
When loading a url:加载 url 时:
Using an htaccess file is a common solution to this problem:使用 htaccess 文件是解决此问题的常见方法:
from http://altlab.com/htaccess_tutorial.html来自http://altlab.com/htaccess_tutorial.html
This code in particular redirects anyone trying to hotlink an image.此代码特别重定向任何试图热链接图像的人。
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.