ObiHill
ObiHill

Reputation: 11876

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 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.

Upvotes: 0

Views: 331

Answers (2)

Louis Ricci
Louis Ricci

Reputation: 21086

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.

Upvotes: 0

gdoron
gdoron

Reputation: 150253

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.

Upvotes: 2

Related Questions