Results 1 to 14 of 14

Thread: Show IP

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Chile
    Posts
    137

    Question Show IP

    Could someone tell me how to show the ip of the server it's hosted the page? i have dynamic ip and sometimes i need to know the ip of my computer at home when i'm at other place so i would like to have a page to show the current server local ip

    Thanks in advance

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    $_SERVER["SERVER_ADDR"]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Chile
    Posts
    137

    Doesn't work

    It doens't work...
    can you specify more abot how to use that code phpman?


    thanks in advance

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Chile
    Posts
    137
    I get this error:
    Notice: Undefined index: SERVER_ADDR in c:\inetpub\wwwroot\index.php on line 4

  5. #5
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    OK, Try this?:

    PHP Code:
    <?php

    error_reporting
    (E_ERROR);

    $remote_ip getenv("REMOTE_ADDR");

    echo 
    "Remote IP Address (IE: Yours): " $remote_ip;

    ?>
    Call it IP.php

    then go to: http://MySite.com/IP.php

    and it will reveal ur IP, NM where you are, work / home / etc.. well your EXTERNAL IP,,

    If ur work is behind a router / proxy server, it will reveal that ip..

    But ne how, try that
    Wayne

  6. #6
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    wpearsall you should read the question. He wants the server ip address not the user's ip address.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by krammer
    I get this error:
    Notice: Undefined index: SERVER_ADDR in c:\inetpub\wwwroot\index.php on line 4
    What version of PHP do you have? Give this a try:

    Code:
    echo $HTTP_SERVER_VARS['SERVER_ADDR'];
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Originally posted by cpradio
    wpearsall you should read the question. He wants the server ip address not the user's ip address.
    Oh yeh, so he does

    BUT:

    If he uses HTTP_SERVER_VARS[SERVER_ADDR]

    it will show how he called his page.. IE:
    http://MySite.com/MyPHPFile.php -> MySite.com
    http://*.*.*.*/MyPHPFile.php -> *.*.*.*

    Unless he has VHosts setup, then it will return his virtual host address...

    And then u still need to know the address, to get to the page?
    Wayne

  9. #9
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by wpearsall
    Oh yeh, so he does

    BUT:

    If he uses HTTP_SERVER_VARS[SERVER_ADDR]

    it will show how he called his page.. IE:
    http://MySite.com/MyPHPFile.php -> MySite.com
    http://*.*.*.*/MyPHPFile.php -> *.*.*.*

    Unless he has VHosts setup, then it will return his virtual host address...

    And then u still need to know the address, to get to the page?
    When I ran that code (the one I supplied) on my server, I got the IP. And I used this address: http://www.vbshelf.com/test.php

    See for yourself.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by krammer
    I get this error:
    Notice: Undefined index: SERVER_ADDR in c:\inetpub\wwwroot\index.php on line 4
    how are you using it?

    also try this

    echo $_ENV["SERVER_ADDR"];

    lests see the code and what version of php do you have?

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Chile
    Posts
    137
    The Hobo: Nice ! Thank you very much that worked... i don't know what happened with the other code.... Thanks a lot man!!!

    CYA

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by krammer
    i don't know what happened with the other code
    Support for the superglobals ($_SERVER, $_POST, $_COOKIE, etc) was added in 4.1. If you have a version of PHP lower than that, that would be why it wasn't working.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    Member
    Join Date
    Mar 2002
    Posts
    37

    umm

    Why not just use $HTTP_HOST ?

  14. #14
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: umm

    Originally posted by SystemShock
    Why not just use $HTTP_HOST ?
    Because it's deprecated.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width