开发者

PHP If Script is being fetched by URL

开发者 https://www.devze.com 2023-01-08 14:49 出处:网络
I have an RSS feed, users will be using it to rip content to display on there site. However I need todo a check that the site doing so has access.

I have an RSS feed, users will be using it to rip content to display on there site. However I need todo a check that the site doing so has access.

Its just occurred to me that I have no idea in PHP how to detect if the script is being read by a server and what the URL is of the fetch.

Is i开发者_开发知识库t possible?


The best approaches for this are...

  1. Give each rss reader it's own key (or maybe even login, password). You'll be sure that nobody can read your RSS without key.
  2. You can allow reading rss only from ips from allowed list.
  3. Checking referer, but it's not a good idea, because referer could be faked as well as any HTTP header.


Strictly speaking it is not, unless the server/client goes to lengths to identify themselves (HTTP authentication, custom header, data provided in a POST request, etc.).


It is possible to tell the IP address of the fetching server using $_SERVER["REMOTE_ADDR"]. Whether anything else is possible to tell depends on the methods your users use to "rip" the feed.


$_SERVER["REMOTE_ADDR"] gives you the IP of the requesting server. By checking this you could implement a basic access control check.

0

精彩评论

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