Break up $_SERVER['HTTP_USER_AGENT'] into array

Discussion in 'PHP' started by Python, Sep 3, 2007.

  1. #1
    I am creating a traffic analysis script. I am aware of $_SERVER['HTTP_USER_AGENT'] however I need to break that up into its separate parts so I can then insert them into a database.

    From it I need the following information:
    Browser name
    Browser version
    Language
    Operating system/Platform

    Is there anyway I can break it up to put these into an array? Perhaps there is already a function out there which will do it.

    Thanks
     
    Python, Sep 3, 2007 IP
  2. Kuldeep1952

    Kuldeep1952 Active Member

    Messages:
    290
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #2
    There is a PHP function split() which can split a string based
    on a separator and create an array. But this may not help you.

    Your best bet would be to check for the existence of common type
    of these elements.
     
    Kuldeep1952, Sep 3, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    nico_swd, Sep 4, 2007 IP
  4. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    get_browser() requires a browscap.ini config file in order to work.

    If you get a warning from php when trying to use the function, you can find a browscap.ini file here: http://browsers.garykeith.com/downloads.asp

    Be sure to download the PHP version.

    Then, make sure you set the location in php.ini:

    browscap = "/path/to/browscap.ini"

    note: there is no e in browscap!

    You can verify that the value is set by looking at the output from phpinfo()
     
    sea otter, Sep 4, 2007 IP
  5. webw

    webw Peon

    Messages:
    32
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    webw, Sep 4, 2007 IP
  6. Jeewhizz

    Jeewhizz Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You are probably better off using something like this:

    http:// pear.php.net/package/Net_UserAgent_Detect
     
    Jeewhizz, Sep 6, 2007 IP
  7. Python

    Python Well-Known Member

    Messages:
    680
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    120
    #7
    Python, Sep 6, 2007 IP