views:

31

answers:

3

Hello,

Let me introduce to the situation we had to face it and the core of the question.

We needed in our project to change the "localhost" to be something else like "newdomain-localhost.com", so we changed the hosts file (in Windows) and everything worked.

We reached the wall of Facebook with its sharer, where you need to get the site into a whitelist if you want to share content like flash. It's allright with the production server, but what happens in the dev enviroment?

My question is: if I change the hosts file to get localhost into something like "newdomain-localhost.com", when a request is thrown from my local machine to a service like Facebook, Facebook will take the domain "newdomain-localhost.com" or directly the public IP of my machine (which in this case is fixed, but it can be dynamic)?

Let me add that I think it perfectly makes sense to say that the hosts is something that affects locally, and the service receives the public IP instead of the domain name.

Correct?

+2  A: 

I'm not certain I grasp your question, but my best guess is it boils down to:

If I rename localhost to newdomain.example.com within the hosts file do external sites see that?

And the answer is catagorically: no

Your hosts file is simply used by your local machine to resolve addresses - it is not visible to anyone/anything outside of your local machine. Now if you put that data within a public DNS it would be a different story - but I won't complicate things by going off on that tangent * admires tangent *

Rudu
A: 

What exactly is your project doing? Are you talking about Facebook connect? What you are saying will work fine on your computer for Facebook connect, but only on the computers where you've modified the hosts file.

If you have Facebook connect set so your application goes to http://www.production.com, then you just need to add a line to your hosts file saying www.production.com is 127.0.0.1. When you click on the connect button the login window opens and that redirects you to the url http://www.production.com to set your connect cookies. Since your computer thinks that the IP for that site is 127.0.0.1 and since cookies are stored with host names and not IPs that works fine.

Jason Goemaat
The enviroment is development and Facebook is the site we're working with. Thanks!
Sebastian
+1  A: 

What happens is the following: if you add/change something to your hosts file (/etc/hosts on linux, %windir%\system32\drivers\etc\hosts on windows), only your local PC will act differently because it first looks in this hosts file when it tries to find an ip-address for a host name. The host name will be sent with the HTTP request, so web servers can act differently for different host names with the same ip-address.

You might be interested in reading a bit about network address resolving (e.g. http://en.wikipedia.org/wiki/Domain_Name_System )

ivy