开发者

Restrict file access to current site only

I have a file that is PHP based but outputs and encodes it se开发者_StackOverflow中文版lf as JSON.

Also it has a .json file type.

But people are currently accessing it and I don't want them too if they are not on my site.

Is it possible with PHP to achieve this?


You probably want to check the inbound Referer header, and if it doesn't match your site, then drop the traffic. There are ways to get around this, of course, but it will block casual use.


No, this isn't possible, unless you force people to register with your site and enter later on a grant-access token (a string, which can't be guessed).

An incomplete solution would be to check the referrer. Unfortunately, not all browsers forward the referrer. Access the referrer like this:

$_referer = $_SERVER["HTTP_REFERER"];

and is a complete URL like this:

http://www.google.de/search?hl=en&q=Macintosh
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜