Solved

Getting browser information from an array

Posted on 2007-04-09
2
214 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

632 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