Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Shouldn't the value match the IP of the computer that's requesting the script regardless of the fact that it's the same computer that's hosting the script?

share|improve this question

migrated from stackoverflow.com Aug 26 '11 at 17:59

This question came from our site for professional and enthusiast programmers.

12  
"That's when I run PHP locally." totally answers your own question. No? –  Tomalak Aug 26 '11 at 12:35
    
No, it doesn't. –  Emanuil Rusev Aug 26 '11 at 13:01
2  
Please edit in the URL you're accessing as well, or a facsimile of it, and possibly some more information. As it stands now the question is of very low quality, and risk being closed as such. –  Lasse V. Karlsen Aug 26 '11 at 13:10
    
If you feel that the question adds no value then go ahead and close it. I got the answer I was looking for. –  Emanuil Rusev Aug 26 '11 at 13:17
2  
Far fetched != impossible. Once the OP stated he doesn't know, it doesn't matter how far fetched it sounds even if it's coming from a high reputation user. –  Rikudo Sennin Aug 26 '11 at 16:06
show 2 more comments

4 Answers

up vote 7 down vote accepted

Because when you run PHP locally every request you make will come from your machine, which happens to have a remote (or in this case, local) address of... wait for it.... 127.0.0.1 (== localhost).

Elaboration: Let's assume for a second you have no internet connection, nothing at all, no WiFi, no cable. The local connection would still work. Why? because it would be stupid to require internet connection for local affairs. Instead, the connection comes from the server itself which means, you will see localhost or 127.0.0.1 as the remote address, because that's the remote address of the server, relatively to the server.

share|improve this answer
1  
Did you ever watch "How I met your mother"? :p –  genesis Aug 26 '11 at 12:38
    
That's the thing. My machine has a remote address. Why do I get the local "127.0.0.1" instead of it? –  Emanuil Rusev Aug 26 '11 at 12:58
    
What do you mean by "has a remote address"? Unless you've borked your network setup, your machine also has 127.0.0.1 as an address, and this is used as the source address. –  Lasse V. Karlsen Aug 26 '11 at 13:00
    
I mean that it has a regular address that looks something like 95.87... –  Emanuil Rusev Aug 26 '11 at 13:02
    
Still... 127.0.0.1 is obviously the one used. –  Lasse V. Karlsen Aug 26 '11 at 13:02
show 6 more comments

It is a local connection.

The connection is being made locally. You local IP address for your localhost is 127.0.0.1.

No connections are being made through any other network other than your localhost.

share|improve this answer
add comment

because localhost === 127.0.0.1

share|improve this answer
add comment

The reason for this is that you're talking to 127.0.0.1.

When talking to a network device (local machine or otherwise), packets has to have a source address, and an address is picked that will be available in the network you're communicating over.

So the source address used depends on the target address being communicated with.

Since the server is reporting that you're coming from 127.0.0.1, you will have to be talking to 127.0.0.1, because that's the only target address where that source address would've been picked.

If you had talked to your machine using its IPv6 local address (::1), then you would've seen ::1 reported as the source address as well.

However, in order to see the 95.87... address, you need to be talking to that address as well.

You can try that by simply replacing the hostname or localhost or whatever you wrote in the URL with 95.87... for the hostname part, and it should report that you're also coming from that address.

My guess is that you're doing http://machinename, which is resolving to 127.0.0.1, and thus the 127.0.0.1 address was picked as the source address as well.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.