开发者

how to block websites to copy php result in my server?

this is my code example:

$('#list').load('/file.php?id=25');

how to block anot开发者_运维知识库her websites to access and get result from file.php ?

thanks


Due to the same-origin policy, JavaScript code served in the context of another domain can not access your content.

However, a server-side script can always download the website. What you can do against that is:

  • Not serve the website in the first place. I'm assuming that's not an option
  • Require passwords from trusted users. Note that those users can also store their passwords at a remote server.
  • Require CAPTCHAs for each visit. This is bound to annoy your legitimate visitors.
  • Require signed hard-/software. Since there is no easy way to do that right now, you'll need every visitor to install custom and/or signed hard- and software. This is not feasible.


By deleting file.php or by protecting it with a password. There is no other reliable way. If you have a resource publicly accessible on the web, there is always the risk of it being scraped.

The example you show, however, will not work for other sites anyway, because normal Ajax requests can't be cross-domain.


If you have a login system in place, start a session in file.php and check if the user is logged in - the session cookie will be sent when the Ajax call is made.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜