0

So let's assume we have two web sites:

  1. one is hosted on a public web hosting account with a public domain name e.g. mydomain.com

  2. the other is hosted on a local computer e.g. my laptop, but is configured to run with the same hostname e.g. mydomain.com, using Apache Virtual Hosts

So both will have the same window.documentURI or window.location.href.

Is there a way I can determine, using Javascript, which Web site is hosted publicly and which one is hosted privately?!

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.

ObiHill
  • 10,952
  • 18
  • 82
  • 127

2 Answers2

2

Is there a way I can determine, using Javascript, which Web site is hosted publicly and which one is hosted privately?!

No. How exactly do you expect it to know? javascript has a very limited access control to the hosted machine.

gdoron is supporting Monica
  • 142,542
  • 55
  • 282
  • 355
  • I was thinking maybe I could somehow retrieve the IP address from the server and if it's `127.0.0.1` then I'll know it's private. Trying to figure out how I'm going to do that though. – ObiHill Mar 21 '13 at 18:53
  • @ChuckUgwuh, I don't think you will get that address but the real IP address of the laptop, you can hardcode that value if you wish using a solution like [this](http://stackoverflow.com/a/810461/601179). By the way, why do you need it? – gdoron is supporting Monica Mar 21 '13 at 18:54
  • I tried a couple of things on the server-side but can't seem to find a solution. I guess I'm going to have to advise clients to obfuscate their code to provide additional security. I'm keep looking though. – ObiHill Mar 22 '13 at 00:22
0

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. You would compare the two results.

Louis Ricci
  • 20,328
  • 5
  • 45
  • 61
  • Ok. Is there no way to get the loopback IP address, using javascript, from the local web server?! – ObiHill Mar 21 '13 at 19:01
  • @Chuck Ugwuh - On Windows and Internet Explorer you could use ActiveXObject loading inside of JavaScript (read: JScript) but in the general case, no – Louis Ricci Mar 21 '13 at 19:06
  • That's way too much hassle for what I'm looking to do. Thanks though. – ObiHill Mar 21 '13 at 19:24