Static IP offline

al404

macrumors 6502
Original poster
Apr 24, 2011
436
21
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?
 

larkost

macrumors 6502a
Oct 13, 2007
536
1
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.
 
Comment

al404

macrumors 6502
Original poster
Apr 24, 2011
436
21
Novara, Italy
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
 
Comment

ScoobyMcDoo

macrumors 65816
Nov 26, 2007
1,189
35
Austin, TX
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.
 
Comment

al404

macrumors 6502
Original poster
Apr 24, 2011
436
21
Novara, Italy
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
 
Comment

ScoobyMcDoo

macrumors 65816
Nov 26, 2007
1,189
35
Austin, TX
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?
 
Comment

al404

macrumors 6502
Original poster
Apr 24, 2011
436
21
Novara, Italy
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
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.