Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    46
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Display User's Ip Address, Browser Type, Browser Resolution, etc..

    I would like to develop a simple 1 page site where it will display the users IP Address, Browser Type, Browser Resolution, and whether Javascript is enabled or disabled..

    I have this for the first 2

    PHP Code:
    <?php
    $ip 
    getenv('REMOTE_ADDR');
    echo 
    "<p>IP: $ip</p>";
    ?>

    <?php
    $browser 
    getenv('HTTP_USER_AGENT');
    echo 
    "<p>Browser Type: $browser</p>";
    ?>
    its pretty simple 4 right now just tryin to get everythin to work.. is there any other type of useful information i can add?

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    It might be worth looking at
    http://php.net/manual/en/function.get-browser.php
    to see what other browser info you can use (such as version number and so on)
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Resolution and javascript detection cannot be done with just php. PHP does not care one bit about the browser itself, just what the browser tells it about itself. Using browscap you could actually find out if JS is supported by the browser, but not if its actually enabled.

    As for useful information, the ip and user agent have limited use. Since these are provided to PHP by the client, there is no guarentee on its validity.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    New Coder
    Join Date
    Apr 2008
    Posts
    46
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JAY6390 View Post
    It might be worth looking at
    http://php.net/manual/en/function.get-browser.php
    to see what other browser info you can use (such as version number and so on)
    thx! I see it shows Javascript = 1 and im guessing if theres no javascript it would be Javascript = 0.. I'm not to good with php but how would I change the value from 1 to Yes and 0 to No?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by JaymeNYC View Post
    thx! I see it shows Javascript = 1 and im guessing if theres no javascript it would be Javascript = 0.. I'm not to good with php but how would I change the value from 1 to Yes and 0 to No?
    No, that only indicates if JS is supported. Disable you're JS, it should still indicate a 1.
    To change it to yes and no:
    PHP Code:
    function convertBoolToYesNo(&$val$key)
    {
        if (
    is_bool($val))
        {
            
    $val = !$val 'No' 'Yes';
        }
    }

    $aItems get_browser();
    array_walk($aItems'convertBoolToYesNo'); 
    Something like that.

    Edit:
    Change the algorithm, I believe get_browser returns several string values as well.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    New Coder
    Join Date
    Apr 2008
    Posts
    46
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    No, that only indicates if JS is supported. Disable you're JS, it should still indicate a 1.
    To change it to yes and no:
    PHP Code:
    function convertBoolToYesNo(&$val$key)
    {
        if (
    is_bool($val))
        {
            
    $val = !$val 'No' 'Yes';
        }
    }

    $aItems get_browser();
    array_walk($aItems'convertBoolToYesNo'); 
    Something like that.

    Edit:
    Change the algorithm, I believe get_browser returns several string values as well.
    some of those examples didnt work 2 well.. since the Javascript wont let me know if its actually enabled how do I check that? im going to be using this site for users so i can easily find out what browser they r usin and if javascript is enabled

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    The only way to check if JS is enabled is to use js to set a cookie and let php retrieve it. Otherwise, you cannot detect this. My first post in this thread indicated that browser specific configurations are not known to php unless provided to it. Otherwise, PHP does not care about the browser in the least.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    New Coder
    Join Date
    Apr 2008
    Posts
    46
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    The only way to check if JS is enabled is to use js to set a cookie and let php retrieve it. Otherwise, you cannot detect this. My first post in this thread indicated that browser specific configurations are not known to php unless provided to it. Otherwise, PHP does not care about the browser in the least.
    What would u say is the best way to get the IP,Browser Type, and OS Version?

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Those three can be retrieved from the REMOTE_ADDR and HTTP_REFERER. Both are technically spoofable, but not really a big deal to be quite honest.
    The splitting up of information for the HTTP_REFERER is where get_browser is quite handy. OS version is included as a result under 'platform', and 'browser' for the browser type.
    With IP, you can try to get a more accurate reading by implementing techniques using HTTP_VIA and HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR and whatnots. These help to eliminate things like proxy servers and internal NAT translations on lans. Just google up for 'determine real IP with php' or something like that, and you should get a few articles regarding the usage of these.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    New Coder
    Join Date
    Apr 2008
    Posts
    46
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    ill try this out soon thanks


  •  

    Posting Permissions

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