LiveWire Peer Support Network

Printable Version of Topic "PHP issue"

- LiveWire Teen Forums & College Forums (http://www.golivewire.com)
-- (http://www.golivewire.com/forums/support-technical.html)
--- Web Design & Search Engine Optimization (http://www.golivewire.com/forums/forum-200-s-0.html)
---- PHP issue (http://www.golivewire.com/forums/peer-yetepin-support-a.html)


-- Posted by pleaseremove at 1:29 pm on Dec. 30, 2008

OK, usual reminder, only reply if you have something useful to add, people saying "Wat?" etc will have their posts removed.

I am working in PHP on putting in better logging into my error handling system. As part of this i want to get out the users browser name and version and their OS.

So we after something like Firefox 3 and Windows Vista in my case.

Now I know we can get the user agent which technically does contain this information, although it requires some processing first. Details are often stored in different places depending on OS and browser.

Obviously I would be using get_browser() but this is not supported in the installation of PHP I have and I don't have the relative permissions to change this.

Any ideas on how best to do this?

Note, I want to do this in PHP, not Javascript.

Cheers guys.


-- Posted by Mediocre at 1:34 pm on Dec. 30, 2008

PEAR has a popular package that does this: http://pear.php.net/package/Net_UserAgent_Detect/

Ugly code, but meh.


-- Posted by pleaseremove at 1:56 pm on Dec. 30, 2008

Quote: from Mediocre at 9:34 pm on Dec. 30, 2008


PEAR has a popular package that does this: http://pear.php.net/package/Net_UserAgent_Detect/

Ugly code, but meh.


That looks like exactly what I'm looking for. I don't suppose you have any experience in implementing this? As per usual Pear's documentation is very poor and I am having a hard time chasing docs after docs and not got it working as yet.


-- Posted by Mediocre at 2:06 pm on Dec. 30, 2008

Basically:

Code:
require_once('Detect.php');

echo 'OS: '.Net_UserAgent_Detect::getOSString().'
Browser: '.Net_UserAgent_Detect::getBrowserString();


-- Posted by pleaseremove at 2:18 pm on Dec. 30, 2008

It was looking good, but unfortunately it isn't quite what I am after. It doesn't do much more than reg ex the user agent. At current, when asking for browser and OS i am getting the following:

Browser: Mozilla/Netscape 6.x
OS: Microsoft Windows NT

I am looking for something that actually figures out I have Vista and Firefox 3.


-- Posted by Mediocre at 2:34 pm on Dec. 30, 2008

I don't see how it's possible to determine browser/OS except through the user agent string.


-- Posted by pleaseremove at 3:24 pm on Dec. 30, 2008

Quote: from Mediocre at 10:34 pm on Dec. 30, 2008


I don't see how it's possible to determine browser/OS except through the user agent string.

Oh, i know this has to be done through the user agent, it is more than i need something human readable. I dont want it to spit back that i have Windows NT 6.0 or something, I want it to work out Vista. I guess im more looking for smart conversion tables than anything else. The feature is in PHP and there are even ways to get updates for such tables, but it is turned off in my install.


-- Posted by jkjslkjind at 11:37 pm on Dec. 30, 2008

$_SERVER['HTTP_USER_AGENT']

try that :)


-- Posted by jkjslkjind at 11:39 pm on Dec. 30, 2008

and if you wanna find browser

if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE') !== false)
  echo 'Internet explorer';

remember, you must compare strpos to false. NOT to true.
you can use ===false or !==false


-- Posted by Macropiper at 11:19 pm on Jan. 21, 2009

I would use regular expressions to extract the information out of the user agent, best place to start is by obtaining a nice long diverse list of user agents and keep working at the code till it processes them all perfectly.


www.golivewire.com