View Full Version : Stripping OS information from HTTP_USER_AGENT
nobody
March 30th, 2005, 04:37 PM
Hey guys,
I'm using PHP's $_SERVER['HTTP_USER_AGENT'] to determine the users OS and Browser and all that. What I was wondering if any of you awesome gurus out there knew a decent way to strip out just the OS portion of that.
Outputs look like this:
Linux/Ubuntu:
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20041013 Firefox/0.9.3 (Ubuntu)
WinXP:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)
Mac:
(If anyone has a mac and wouldn't mind going to www.ratherlargefire.com so that your info is logged, and telling me that you went that'd be great.)
So that's how it outputs. Anyone have any idea, or a point in the right direction? I could use some strpos stuff with some if statements and all, but there isn't enough information right now for that, so it'd be better if there was another way that would do it without me hardcoding in options.
Thanks :)
CyanBlue
March 30th, 2005, 10:35 PM
This looks like a good one to read...
http://www.zend.com/codex.php?id=1290&single=1
nobody
March 30th, 2005, 10:38 PM
Thank you very much CyanBlue, I was searching all day for something like this :)
CyanBlue
March 30th, 2005, 11:05 PM
There are many classes that does what you are looking for as well... ;)
They are pretty much the same, but you can use those class files to get rid of ridiculous if statements... :D
http://phpsniff.sourceforge.net/docs/__filesource/fsource_phpSniff__phpSniff.class.php.html
http://www.koders.com/php/fid6C907903EEAFA7F6FDE767DFD4F7C525D440F174.aspx
http://sourdough.phpee.com/api/__filesource/fsource_sourdough_net_Sd_NetSd_Yabd.class.php.html
nobody
March 31st, 2005, 11:37 AM
Those look promising. Thanks for findind all the for me CyanBlue, that's really cool =) I appreciate it. Just a question though, I'm just making a viewer log for my site, so if I put in a big file like this just to detect the browser or OS is it going to slow down my sites loading time very much?
CyanBlue
March 31st, 2005, 11:40 AM
Only when you run that specific PHP file, I guess... ;)
But, if you just want to see the log and analyze it, why not use products like Webalizer or something??? Just a thought...
and I'd appreciate it if you call me CyanBlue not Cyan... I hate people calling me that... ;)
nobody
March 31st, 2005, 11:42 AM
Eh, I figured making my own would be a better learning process. Whenever there's something I want I just make it, poorly. I figure maybe it'll decrease my level of php stupidity eventually.
Sorry about the cyan thing, CyanBlue :P
(Even editing the other times I called you that just cause you're such a helpful fellow)
CyanBlue
March 31st, 2005, 11:52 AM
Oh, you missed 'C' in CyanBlue... See how I can be nasty??? :p
Yup... Totally understood... and I am sure that is a good way to learn PHP... :)
nobody
March 31st, 2005, 11:55 AM
fixed the C :m:
Thanks again for all the links, I always see you helping everyone out, tis very cool of you. Hopefully I'll be half as helpful as you some day :)
CyanBlue
March 31st, 2005, 12:02 PM
Hey... That's how I learn... ;)
nobody
March 31st, 2005, 02:52 PM
Just in case anyone cares, this is what I've come up with thus far
http://www.ratherlargefire.com/logs/index.php
So if anyone that's kind of new to PHP or anything wants a sorta beta low-end visitor tracker let me know, and I'll send you the files and help you edit them as necessary.
Functionality which will eventually be added:
Password Protection
Pagination (Ugh!)
IP Filtering
Operating System Identification
Archives (possibly, I'm storing date information as a PHP string though, so maybe I won't)
Whatever else comes to mind :P
So there ya have it, not too awful for a day and halfs work I suppose.
CyanBlue
March 31st, 2005, 03:43 PM
Looks cool... Good job... :)
nobody
March 31st, 2005, 04:12 PM
Thanks :)
I just realized it sucks in IE but heyyyy who cares :P
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.