Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

al404

macrumors 6502a
Original poster
Apr 24, 2011
555
35
Novara, Italy
HI, as a PHP developer i use my local ip to find if my scripts are running on my local machine or on a server

the problem is that i just find out that once i disconnect from my lan, so no internet connection, i can't find a way to assign a static ip

any solution?
 
Yes, use 127.0.0.1. That is the "loopback" address, and always points at the machine you are running on. You can also use "loalhost", as that aliases to the loopback address.

Vitural hosts take hacking up /etc/hosts.
 
actually i can't use 127.0.0.1, is what i did in the mean while, because i assume that on production server would be recognized by php as valid IP too

ok so i tried to add my network ip to file hosts but it doesn't seem to work
192.168.1.3 localhost
 
ok so i tried to add my network ip to file hosts but it doesn't seem to work
192.168.1.3 localhost

Yea, you don't want to do that - changing localhost is probably a really bad idea.

Instead of looking at the current IP address, to determine where your code is running, can you use the hostname instead? Hostname will not change even if you are disconnected. Well, actually hostnames can be changed by a DHCP server, but you said you were using static IP, so that should not happen to you.
 
but i move the code across iMac and macBook

i don't usually use static ip, but DHCP and my router assign to my macBook and iMac preassigned IP
 
But does your hostname stay constant on each machine?

I may be misunderstanding your intentions here. It appears to me that you are trying to write some code in your scripts to determine which machine your code is currently running on, and then have your code do something specific to that machine. Is this correct?
 
yes is correct, my iMac and macbook is my local environment

actually i think that i can't even retrieve host name with PHP because i have SERVER_NAME, that is my local IP
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.