Php: getting local IP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jezternz
    New Member
    • Jan 2008
    • 145

    Php: getting local IP

    Easy to get the external ip adress, using the $SERVER var, but I want the local ip.
    My situation isnt normal by the way. Basicly im building simple intranet ( i want to run this on a local area network (will be hundreds of people) not on the web, so for logins im gonna be using local ip's, is there any way I can get them easily?
    $HTTP_SERVER_VA RS['HTTP_X_FORWARD ED_FOR'] <- people have said this would work.. but would it actually work in a lan invroment, im not so sure.

    Thanks, Josh
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Even when connecting from a LAN, "$_SERVER['REMOTE_ADDR']" should give you the local IP of the computer that sent the request.

    I doubt "$HTTP_SERVER_V ARS['HTTP_X_FORWARD ED_FOR']" works, as it is on of a few non-standard headers, sent by some proxy servers in an attempt to reveal the actual IP of users trying to hide their identity by going through a proxy.

    Comment

    • Jezternz
      New Member
      • Jan 2008
      • 145

      #3
      oh ok cool thanks heaps.
      So how do you tell pc's apart on the internt if they are shareing the same internet connection? I remember having this problem at school, you log in on one pc, and it logs in on all pcs, because all the pc's had the same external ip? is there any way of getting local ips in that example?

      cheers, Josh

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        When you connect to the internet via a router, the router is essentially working as a proxy server. It makes the request for you and redirects any response to you.

        As such, there is really no way to differentiate between the local machines, as the IP will just point back to the router.
        Unless it explicitly set a header with the local IP address, which I find unlikely due to security reasons.
        Not to mention that a local IP address is useless to anybody outside the LAN.

        If you want to find out, just do a "print_r($_SERV ER)" and see if your local IP is in there somewhere. You would obviously have to try this from a remote computer.

        Comment

        Working...