Go Back   Forum Care Forums > Development Reference Area > Php Development

Reply
 
LinkBack Thread Tools Display Modes
Get the shortened browser / HTTP_USER_AGENT
Old
  (#1)
Wikus Moller
Guest
 
Posts: n/a
Default Get the shortened browser / HTTP_USER_AGENT - 05-14-2007, 03:35 AM

Hi.

I want to strip everything after a / in the HTTP_USER_AGENT for
example: Opera 9.10/blah/blah would become only Opera 9.10

Lets say
$user = $_SERVER["HTTP_USER_AGENT"];
$browser = ("/", $user);

Is this correct?
Isn't something needed in the browser variable?

Thanks
Wikus
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Get the shortened browser / HTTP_USER_AGENT
Old
  (#2)
Myron Turner
Guest
 
Posts: n/a
Default Re: Get the shortened browser / HTTP_USER_AGENT - 05-14-2007, 03:35 AM

Wikus Moller wrote:
> Hi.
>
> I want to strip everything after a / in the HTTP_USER_AGENT for
> example: Opera 9.10/blah/blah would become only Opera 9.10
>
> Lets say
> $user = $_SERVER["HTTP_USER_AGENT"];
> $browser = ("/", $user);
>
> Is this correct?
> Isn't something needed in the browser variable?
>
> Thanks
> Wikus



Are you looking for a regular expression? The user agent strings are
varied. For instance,

Internet Explorer 6:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322; .NET CLR 2.0.50727)

Firefox 2:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1)
Gecko/20061204 Firefox/2.0.0.1

Opera 9.02 on linux:
Opera/9.02 (X11; Linux i686; U; en)

Opera 9.01 on Windows:
Opera/9.01 (Windows NT 5.0; U; en)

The Opera string format which you give ("Opera 9.10/blah/blah") doesn't
show up in the Apache log files I checked. In each case the version
number follows a forward slash, as in the examples above.

As for IE, you can see that it announces itself as Mozilla, so that you
have to look further to find out that it's IE. This is a relic of the
Netscape/IE browser wars.


Look at the source code for a standard javascript sniffer:
http://www.webreference.com/tools/br...avascript.html
It will give you an idea of what's involved in identifying browsers.
Google for php browser sniffers; there are tons of them out there.



--

_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Get the shortened browser / HTTP_USER_AGENT
Old
  (#3)
Sergiu Voicu
Guest
 
Posts: n/a
Default Re: [PHP] Get the shortened browser / HTTP_USER_AGENT - 05-14-2007, 03:35 AM

You have several options:
1. using regular expressions
<?
$user = $_SERVER["HTTP_USER_AGENT"];
preg_match('/^([^\/]+).*/',$user,$matches);
$browser = $matches[1];
?>

2. using arrays
<?
$user = $_SERVER["HTTP_USER_AGENT"];
$tpm = explode('/',$user);
$browser = $tmp[0];
?>

3. using substrings
<?
$user = $_SERVER["HTTP_USER_AGENT"];
$browser = substr($user,0,strpos($user,'/');
?>

Sergiu

Wikus Moller wrote:
> Hi.
>
> I want to strip everything after a / in the HTTP_USER_AGENT for
> example: Opera 9.10/blah/blah would become only Opera 9.10
>
> Lets say
> $user = $_SERVER["HTTP_USER_AGENT"];
> $browser = ("/", $user);
>
> Is this correct?
> Isn't something needed in the browser variable?
>
> Thanks
> Wikus
>

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top