Solved

Getting browser information from an array

Posted on 2007-04-09
2
211 Views
Last Modified: 2010-08-05
I am trying to get the browser and platform names from visitors in PHP. I can't use the get_browser method because its not supported on my server. I have found this:
http://garetjax.info/projects/browscap/

It seems to do what i require. However i'm having trouble getting the information from the array. Heres my code:

// Loads the class
require 'includes/Browscap/Browscap.php';

// Creates a new Browscap object (loads or creates the cache)
$bc = new Browscap('includes/Browscap/cache');

// Gets information about the current browser's user agent
$current_browser = $bc->getBrowser();

// Output the result
$browser = $current_browser['browser'];
$platform = $current_browser['platform'];
echo $browser . "<br />" . $platform;

This just prints nothing. Where am i going wrong?
0
Comment
Question by:alex_wareing
2 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 18876984
You'd might just want to see what plain $_SERVER entries you can use:

echo '<pre>'.var_export($_SERVER, true).'</pre>';

You'd probably should be able to distill the information from $_SERVER['HTTP_USER_AGENT'];

echo $_SERVER['HTTP_USER_AGENT'];

-r-
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 18877042
The class you are using doesnt return an array it returns an object.

$browser = $current_browser->Browser;
$platform = $current_browser->Platform;

you can do a print_r($current_browser) to get the rest of the values .
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question