SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Vancouver Canada
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to show Users IP

    I am writing an article, and need to display the readers IP. How do i do it so it works on PHP 4.0.6 and also the one for 4.3

    Thanks
    Get busy living or get busy dying
    --Stephen King

  2. #2
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try $_SERVER['REMOTE_ADDR']
    - website

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Vancouver Canada
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. that worked. and it's HTTP_SERVER for 4.0.6 right? since _SERVER doesn't work on pre 4.1.0 PHP?
    Get busy living or get busy dying
    --Stephen King

  4. #4
    SitePoint Member
    Join Date
    Feb 2003
    Location
    GMT+5
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI,

    Is it possible to show the host or ISP based on that IP Address?

    Thanks

  5. #5
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You can use gethostbyaddr(). See http://www.php.net/manual/de/function.gethostbyaddr.php for examples. The user notes have some solutions for getting the host of users who are behind a proxy.

  6. #6
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    gethostbyaddr() isn't exactly what he's looking for here. You'd probably need to WHOIS the IP and parse the results to find an ISP. Not sure how you'd do that though

  7. #7
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mac Write
    Thanks. that worked. and it's HTTP_SERVER for 4.0.6 right? since _SERVER doesn't work on pre 4.1.0 PHP?
    Not sure, try $HTTP_REMOTE_ADDR.

    gethostbyaddr() isn't exactly what he's looking for here. You'd probably need to WHOIS the IP and parse the results to find an ISP. Not sure how you'd do that though
    hehe, I second that last part
    - website

  8. #8
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    I had a quick look into it because it would be fun to write some code to do that but I couldn't find any console tools on WinXP Pro to run a WHOIS command on an IP. I'm not into networking in the slightest so my search wouldn't have been very thorough but yeah...

    The closest thing I could find, and I'm not sure what the equivilant on *nix is, but nslookup. This code will return the remote hostname
    PHP Code:
    $foo = `nslookup {$_SERVER['REMOTE_ADDR']}`;
    $foo explode("\n"$foo);

    echo 
    trim(substr($foo[0], 16)); 
    I'm Googling now to find some more info so I'll post as I find it.

  9. #9
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    http://www.codetoad.com/asp_geoip.asp

    That will find the country (not ISP) by the users IP but it's written in ASP.

    http://www.ip2location.com/

    Here is a commercial one that uses PHP & MySQL, but again, not the users ISP.


Bookmarks

Posting Permissions

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