Solved

Getting browser information from an array

Posted on 2007-04-09
2
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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 …

752 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