SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member frankie54's Avatar
    Join Date
    Feb 2001
    Location
    NYC
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    baby steps... displaying IP, browser and so on.

    Just curious if anyone could point me to PHP scripts or resources specifically showing how to display the IP address, browser type and http_referer info from a browser request so that the user see it on the web page they just requested?

    Been poking around all the books I have, and couldn't easily find how to do it.

    Any answers appreciated.

    Frankie
    stay groovy !

  2. #2
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    PHP Code:

    // Get the Browser 
    if(eregi("(opera) ([0-9]{1,2}.[0-9]{1,3}){0,1}",$HTTP_USER_AGENT,$match) || eregi("(opera/)([0-9]{1,2}.[0-9]{1,3}){0,1}",$HTTP_USER_AGENT,$match)) 

    $BName "Opera"$version=$match[2]; 

    elseif(
    eregi("(konqueror)/([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) 

    $BName "Konqueror"$version=$match[2]; 

    elseif(
    eregi("(lynx)/([0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2})",$HTTP_USER_AGENT,$match)) 

    $BName "Lynx "$version=$match[2]; 

    elseif(
    eregi("(links) \(([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) 

    $BName "Links "$version=$match[2]; 

    elseif(
    eregi("(msie) ([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) 

    $BName "Internet Explorer "$version=$match[2]; 

    elseif(
    eregi("(netscape6)/(6.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) 

    $BName "Netscape "$version=$match[2]; 

    elseif(
    eregi("mozilla/5",$HTTP_USER_AGENT)) 

    $BName "Netscape"$version="Unknown"

    elseif(
    eregi("(mozilla)/([0-9]{1,2}.[0-9]{1,3})",$HTTP_USER_AGENT,$match)) 

    $BName "Netscape "$version=$match[2]; 

    elseif(
    eregi("w3m",$HTTP_USER_AGENT)) 

    $BName "w3m"$version="Unknown"

    else
    {
    $BName "Unknown";
    $version="Unknown";
    }

    // $Bname is the browser, $version is the version
    // $HTTP_REFERER and $REMOTE_ADDR are predefined variables
    echo "You are using $Bname $version, your IP is $REMOTE_ADDR and you came from $HTTP_REFERER."

  3. #3
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Nice list. I don't usually get that comprehensive - but may have to copy that .

    Brings another question. Where and how do you store "snippets" of code like this, if at all. I have a folder called "php_dev" that is full of unorganised stuff I've picked up over time - there must be a better way!
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  4. #4
    SitePoint Enthusiast doubli's Avatar
    Join Date
    Sep 2001
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Justin Sampson : I tried this code which was great, only I am using IE 6 and it just said the version number (ie 6.0) and not the words ... Internet Explorer

    Any ideas?
    One of lifes luxuries ...

  5. #5
    SitePoint Zealot
    Join Date
    Aug 2001
    Location
    North Carolina
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try just:
    PHP Code:
    print($HTTP_USER_AGENT); 
    to see what IE is actually telling your webserver...
    edit: duh, left off semicolon...
    Andrew Thompson
    VPHost.com, part of the Untapped Resources Network.

  6. #6
    SitePoint Member frankie54's Avatar
    Join Date
    Feb 2001
    Location
    NYC
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wow is all I can say!!

    Thanks Justin for a speedy reply. I will try it tonight and report my luck.

    BTW, Are the two variables $REMOTE_ADDR and $HTTP_REFERER taken directly from the Apache log?

    Frankie.
    stay groovy !

  7. #7
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    those are php enviroment variables.
    $REMOTE_ADDRESS shows the users ip
    $HTTP_REFERER shows the referer address
    $HTTP_USER_AGENT shows the browser, and OS of the user

    No need for all that other code that justin used.
    just echo those 3 variables, and your all set.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  8. #8
    SitePoint Member frankie54's Avatar
    Join Date
    Feb 2001
    Location
    NYC
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    some findings

    To all who answered, thanks. Got it working just fine.

    I didn't realize, but a lite difference with Defender1's
    post, the variable $REMOTE_ADDRESS didn't appear
    to work for me.

    $REMOTE_ADDR is just fine.
    stay groovy !

  9. #9
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe, oops. type.
    yea, it's $REMOTE_ADDR
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


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
  •