PHP If Script is being fetched by URL
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...
- 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.
- You can allow reading rss only from ips from allowed list.
- 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.
精彩评论