简体   繁体   English

使用Javascript确定网站是公共还是私有

[英]Using Javascript to determine if Web site is public or private

So let's assume we have two web sites: 所以我们假设我们有两个网站:

  1. one is hosted on a public web hosting account with a public domain name eg mydomain.com 一个托管在具有公共域名的公共网络托管帐户上,例如mydomain.com

  2. the other is hosted on a local computer eg my laptop, but is configured to run with the same hostname eg mydomain.com, using Apache Virtual Hosts 另一个托管在本地计算机上,例如我的笔记本电脑,但配置为使用相同的主机名运行,例如mydomain.com,使用Apache虚拟主机

So both will have the same window.documentURI or window.location.href . 因此两者将具有相同的window.documentURIwindow.location.href

Is there a way I can determine, using Javascript, which Web site is hosted publicly and which one is hosted privately?! 有没有办法可以确定,使用Javascript,哪个网站是公开托管的,哪个网站是私有托管的?!

Thanks 谢谢

EDIT 编辑

The reason I need this is I'm finishing up a JQuery Plugin that submits some data to a remote server [analytics basically] and I want to make the feature more secure by preventing spoofing by someone using a local server with the same hostname as the rightful user to mess up the data. 我需要这个的原因是我正在完成一个JQuery插件,它将一些数据提交给远程服务器[基本上是分析]我希望通过防止使用具有相同主机名的本地服务器的人进行欺骗来使该功能更安全。合法用户搞乱数据。

Is there a way I can determine, using Javascript, which Web site is hosted publicly and which one is hosted privately?! 有没有办法可以确定,使用Javascript,哪个网站是公开托管的,哪个网站是私有托管的?!

No. How exactly do you expect it to know? 究竟你怎么能指望它知道吗? javascript has a very limited access control to the hosted machine. javascript对托管计算机的访问控制非常有限。

Not without the help of a third party service. 并非没有第三方服务的帮助。

Your javaScript could send two AJAX queries: 1) to return the client's public IP 2) to return the public DNS IP of the domain. 您的javaScript可以发送两个AJAX查询:1)返回客户端的公共IP 2)以返回域的公共DNS IP。 You would compare the two results. 你会比较两个结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM