Static IP offline

Discussion in 'macOS' started by al404, Jun 13, 2012.

  1. al404 macrumors 6502

    al404

    Joined:
    Apr 24, 2011
    Location:
    Novara, Italy
    #1
    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?
     
  2. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #2
    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.
     
  3. al404 thread starter macrumors 6502

    al404

    Joined:
    Apr 24, 2011
    Location:
    Novara, Italy
    #3
    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
     
  4. ScoobyMcDoo macrumors 65816

    Joined:
    Nov 26, 2007
    Location:
    Austin, TX
    #4
    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.
     
  5. al404 thread starter macrumors 6502

    al404

    Joined:
    Apr 24, 2011
    Location:
    Novara, Italy
    #5
    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
     
  6. ScoobyMcDoo macrumors 65816

    Joined:
    Nov 26, 2007
    Location:
    Austin, TX
    #6
    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?
     
  7. al404 thread starter macrumors 6502

    al404

    Joined:
    Apr 24, 2011
    Location:
    Novara, Italy
    #7
    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
     
  8. ScoobyMcDoo macrumors 65816

    Joined:
    Nov 26, 2007
    Location:
    Austin, TX
    #8
    I'm not a PHP developer, but I do know how to use google. I just googled 'php hostname' and clicked on the first hit. Hope it helps.
     

Share This Page