Solved

Getting browser information from an array

Posted on 2007-04-09
2
209 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now