Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting browser information from an array

Posted on 2007-04-09
2
Medium Priority
?
215 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

722 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