SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 47
  1. #1
    SitePoint Enthusiast Diamax's Avatar
    Join Date
    Jul 2002
    Location
    North America
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How Do I Display the ISP Hostname of the Visitor?

    Hello everybody!

    I have this website. and on one page I setup this php script that shows the IP address of the visitor along with the browser that the visitor is using.

    Now there is another thing that I want to show to the visitor and that is the hostname if their ISP.

    Say the IP address of a visitor is: 123.456.78.90
    and their hostname is something like: Washington-HSE.bell.com

    I want to display that information to the visitor, so it would show on the page.
    I'm not a php guru, but so far I managed to use any script that I found on the internet. However I wasn't able to find one that shows the hostname, all of them are about the IP address.

    I wonder if you guys can help me with it, I also looked up on the forums but didn't find the answer to my question...

    THANK YOU!
    Duras mx

  2. #2
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to look at gethostbyaddr

  3. #3
    SitePoint Enthusiast Diamax's Avatar
    Join Date
    Jul 2002
    Location
    North America
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Swdev! Thank you for reply!

    I already tried that... it returns the IP address...

    However, here is the piece of php code that I'm using:

    <?php
    $hst = $_SERVER["HTTP_HOST"]; // This shows the domain name where the website is.
    $uri = $_SERVER["REQUEST_URI"]; // This line shows the name of the requested page.
    $rmt = $_SERVER["REMOTE_ADDR"]; // This shows visitor's IP address.
    $br = $_SERVER["HTTP_USER_AGENT"]; // This shows the browser version the visitor is using.

    echo "<font color='#A00000'>Your IP address is/font><br/><font color='#FF0000'> $rmt \n <br/>
    <font color='#A00000'>The browser you are using is/font><br/> $br<br/>";
    ?>
    Duras mx

  4. #4
    Free Geek computerages's Avatar
    Join Date
    Oct 2004
    Location
    /dev/null
    Posts
    1,071
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Diablomax

    I already tried that... it returns the IP address...
    try this one out:
    PHP Code:
    $host gethostbyaddr($_SERVER['REMOTE_ADDR']); 

  5. #5
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i found this
    PHP Code:
    <?php
    // For Linux...

    function gethost ($ip) {
     
    $host = `host $ip`;
     return ((
    $host end explode (' '$host)) : $ip));
    }

    // For Win32...

    function nslookup ($ip) {
     
    $host split('Name:',`nslookup $ip`);
     return ( 
    trim (isset($host[1]) ? str_replace ("\n".'Address:  '.$ip''$host[1]) : $ip));
    }
    ?>
    it will do what you want BUT remember its executing command as shell/command prompt on *NIX/Windows. so you should have SAFE MODE off (i think)
    ok here's where i found it.
    http://ca.php.net/gethostbyaddr

    it gets the output from these command then you can use regular expression to get what you want

    hope this helps

  6. #6
    SitePoint Enthusiast Diamax's Avatar
    Join Date
    Jul 2002
    Location
    North America
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow guys!
    I'm impressed by the speed that you reply to my thread... almost can't keep up.
    Hi Computerages... same thing, that returns the IP
    Hello Jas! for some reason your solution doesn't work for me. I'm using WinXP for the server, and I tried the Win version of your code. It doesn't return anything, not even an error.
    Duras mx

  7. #7
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, first check your safe mode is off,
    second just try to run
    PHP Code:
    'nslookup 127.0.0.1' 
    and see if it does anything. this would give a heads up. if it does then you can make your own function. RIGHT??

  8. #8

    Join Date
    Oct 2003
    Location
    uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by http://www.php.net/manual/en/function.gethostbyaddr.php
    Returns the host name of the Internet host specified by ip_address or a string containing the unmodified ip_address on failure.
    I guess the IP in question couldnt be resolved, which is probably the case as you are trying it locally.

  9. #9
    SitePoint Enthusiast Diamax's Avatar
    Join Date
    Jul 2002
    Location
    North America
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Drzoid!
    ok my setup... i have couple of computers on the network.
    One of them is the webserver, another is this computer that I'm using, and I'm trying to access my website from the internet, using the domain name and not the internal ip address of the webserver, that is on the network.

    Jas!
    I think I'm not quite getting what you're trying to tell me... my bad.
    I don't know what you mean by "check your safe mode is off"
    About writting my own function... consider me a noob, that might be something simple, but I guess I don't know how to do it.

    By the way... this is the page that I'm trying to setup:
    http://diamax.no-ip.com/admincenter/
    Duras mx

  10. #10

    Join Date
    Oct 2003
    Location
    uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I am confused .... where are you running the non-working gethostbyaddr()?

  11. #11
    SitePoint Enthusiast Diamax's Avatar
    Join Date
    Jul 2002
    Location
    North America
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The computer that I am using now to reply to you guys, is just one on the network.
    The webserver computer is in another room, and I never use that for anything else, it is exclusively used as a webserver.
    Duras mx

  12. #12
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok try this code and see what the output is
    PHP Code:
    if(ini_get('safe_mode'))
    {
        echo 
    'safe mode on';
    }
    else
    {
        echo 
    system('nslookup 127.0.0.1');    

    EDIT: correction of code

  13. #13

    Join Date
    Oct 2003
    Location
    uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You probably cant resolve it, because there is no DNS server which holds its record, right?

  14. #14
    SitePoint Enthusiast Diamax's Avatar
    Join Date
    Jul 2002
    Location
    North America
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow... it says "safe mode on"
    Duras mx

  15. #15
    SitePoint Enthusiast Diamax's Avatar
    Join Date
    Jul 2002
    Location
    North America
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Server: UnKnown Address: 192.xxx.xxx.xxx

    That's what it says...
    Duras mx

  16. #16
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then if you want you can turn off the safe mode (NOT A GOOD IDEA THOUGH IF YOU DONT TAKE PROPER CARE).
    you can turn it off in php.ini (if in your control)

  17. #17
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Diablomax
    Server: UnKnown Address: 192.xxx.xxx.xxx

    That's what it says...
    that's ok(i think because you are on network). now try to put an ip address that you know has something like you want and test that ip

  18. #18

    Join Date
    Oct 2003
    Location
    uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Diablomax
    Server: UnKnown Address: 192.xxx.xxx.xxx

    That's what it says...
    Then it cant work, http://www.sitepoint.com/forums/show...90&postcount=8

    But it will most definitely work outside.

  19. #19
    SitePoint Enthusiast Diamax's Avatar
    Join Date
    Jul 2002
    Location
    North America
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaswinder_rana
    that's ok(i think because you are on network). now try to put an ip address that you know has something like you want and test that ip
    I don't know what you mean by that... :-(
    Duras mx

  20. #20
    SitePoint Enthusiast Diamax's Avatar
    Join Date
    Jul 2002
    Location
    North America
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by drzoid
    Then it cant work, http://www.sitepoint.com/forums/show...90&postcount=8

    But it will most definitely work outside.
    You mean it will actually work for somebody that is not on the network?? that would be what I want.
    Duras mx

  21. #21

    Join Date
    Oct 2003
    Location
    uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Diablomax
    You mean it will actually work for somebody that is not on the network?? that would be what I want.
    The message you received either means it could not resolve the name for the IP or could not even contact the nameserver (I guess its the latter). It will definitely work in a "real" environment.

  22. #22
    SitePoint Enthusiast Diamax's Avatar
    Join Date
    Jul 2002
    Location
    North America
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I hope it does work...
    Now what is the final piece of code that I should put in?
    I have so much commented code... that I'm not sure what should I leave on.
    Duras mx

  23. #23

    Join Date
    Oct 2003
    Location
    uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    gethostbyaddr($_SERVER['REMOTE_ADDR']); 
    will return a string with the hostname (as long as it can be resolved, otherwise it returns the given IP address).

  24. #24
    SitePoint Enthusiast Diamax's Avatar
    Join Date
    Jul 2002
    Location
    North America
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see, I'l put that in. Thank you!
    Jas! What do you think?
    Duras mx

  25. #25
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tell you what, i don't even know 50% of what drzoid knows and i am serious .
    now, like he said it will work in a real environment then if you have a site hosted on a real server then try uploading this test.php (or whatever) on that and then test it


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
  •