Re: Is there an easy way to divid up HTTP_USER_AGENT?

From: Date: Fri, 05 Jul 2002 14:43:16 +0000
Subject: Re: Is there an easy way to divid up HTTP_USER_AGENT?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-105665@lists.php.net to get a copy of this message
JJ, I don't know of an *easy* way, but this script (with regex's ) isn't too bad; you can figure it out with a little bit of research. /* begin script ereg("^([[:alpha:]]+)/([[:digit:]\.]+)( .*)$", $HTTP_USER_AGENT, $match); $Browser_Name=$match[1]; $Browser_Version=$match[2]; $Browser_Description=$match[3]; If(eregi("msie", $Browser_Description)) eregi("MSIE ([[:digit:]\.]+);, $Browser_Description, $match); $Browser_Name="MSIE"; $Browser_Version = $match[1]; } // end script */ So now, you have a script which gets the Name, Version and Description, and also looks to specify MSIE as the browser. Read up on Regular Expressions, and you can modify this for any browser/version combo. (adopted from Listing 16.3 in Core PHP Programming by Leon Atkinson) -- Chris Garaffa #!/usr/local/lib/php $contact_info["Name"] = "Chris Garaffa"; $contact_info["Email"] = "aquax@optonline.net"; $contact_info["Work"] = "cgaraffa@creativeaim.com"; $contact_info["cell"] = "203.803.9066"; He who calles himself "JJ Harrison" (from <webmaster@tececo.com>) wrote on 7/5/02 10:25 AM: > Because! > > Also the audiance that will probably see the site will highly likely not > have the knowledge or intention to change the user agent var. So my Q > remains. > > To add to my original Q is there seperate vars for browser and OS?

« previous php.general (#105665) next »