Newbie problems using HTTP_USER_AGENT

This is a discussion on Newbie problems using HTTP_USER_AGENT within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello, I am having a problem with a simple script that checks and tells the user what browser they are ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-06-2005
toedipper
 
Posts: n/a
Default Newbie problems using HTTP_USER_AGENT

Hello,

I am having a problem with a simple script that checks and tells the user
what browser they are using.

First of all, the browser string for Internet Exploxer contains the text
msie and the browser string for a Pocket PC version of internet explorer
contain msie AND ppc

The problem is that when browsing my test page using pocket pc the script
still returns Interent Explorer. My script is below, can anyone tell me
how to make it determine correctly when accessing via pocket pc? IT works
ok usign using all the other browsers.

Thanks,

td.

http://www.pocketpcheaven.blogspot.com/


<?
$agent = getenv("HTTP_USER_AGENT");

// check to see if running ie
if (preg_match("/MSIE/i", "$agent")) {
$result = "You are using Microsoft Internet Explorer.";
}
//check to see if running Firefox
else if (preg_match("/Firefox/i", "$agent")) {
$result = "You are using Mozilla Firefox.";
}
// check to see if running opera
else if (preg_match("/Opera/i", "$agent")) {
$result = "You are using Opera.";
}
// check to see if running pocket pc browser
else if ((preg_match("/PPC/i", "$agent")) && (preg_match("/MSIE/i",
"$agent"))) {
$result = "You are using Pocket PC Internet Explorer.";
}
// if anything else just display the browser string
else {
$result = "You are using $agent";
}
?>
<HTML>
<HEAD>
<TITLE>Browser Match Results</TITLE>
</HEAD>
<BODY>
<? echo "<P>$result</P>"; ?>
</BODY>
</HTML>




Reply With Quote
  #2 (permalink)  
Old 02-06-2005
Kelvin Mackay
 
Posts: n/a
Default Re: Newbie problems using HTTP_USER_AGENT

On Sun, 6 Feb 2005 19:14:15 -0000, toedipper
<send_rubbish_here734@hotmail.com> wrote:

> Hello,
>
> I am having a problem with a simple script that checks and tells the user
> what browser they are using.
>
> First of all, the browser string for Internet Exploxer contains the text
> msie and the browser string for a Pocket PC version of internet explorer
> contain msie AND ppc
>
> The problem is that when browsing my test page using pocket pc the script
> still returns Interent Explorer. My script is below, can anyone tell me
> how to make it determine correctly when accessing via pocket pc? IT
> works
> ok usign using all the other browsers.
>
> Thanks,
>
> td.
>
> http://www.pocketpcheaven.blogspot.com/
>
>
> <?
> $agent = getenv("HTTP_USER_AGENT");
>
> // check to see if running ie
> if (preg_match("/MSIE/i", "$agent")) {
> $result = "You are using Microsoft Internet Explorer.";
> }
> //check to see if running Firefox
> else if (preg_match("/Firefox/i", "$agent")) {
> $result = "You are using Mozilla Firefox.";
> }
> // check to see if running opera
> else if (preg_match("/Opera/i", "$agent")) {
> $result = "You are using Opera.";
> }
> // check to see if running pocket pc browser
> else if ((preg_match("/PPC/i", "$agent")) && (preg_match("/MSIE/i",
> "$agent"))) {
> $result = "You are using Pocket PC Internet Explorer.";
> }
> // if anything else just display the browser string
> else {
> $result = "You are using $agent";
> }
> ?>
> <HTML>
> <HEAD>
> <TITLE>Browser Match Results</TITLE>
> </HEAD>
> <BODY>
> <? echo "<P>$result</P>"; ?>
> </BODY>
> </HTML>
>


Try rearranging your code to check for the presence of PPC first - eg

// check to see if running pocket pc browser
if ((preg_match("/PPC/i", "$agent")) && (preg_match("/MSIE/i",
"$agent"))) {
...
// check to see if running ie
if (preg_match("/MSIE/i", "$agent")) {
...
Reply With Quote
  #3 (permalink)  
Old 02-06-2005
toedipper
 
Posts: n/a
Default Re: Newbie problems using HTTP_USER_AGENT

Thanks a million, that done the trick.

td.


"Kelvin Mackay" <kelvin@nospam.sands-design.com> wrote in message
news:opslsj52a5krqzhn@snoopy...
> On Sun, 6 Feb 2005 19:14:15 -0000, toedipper
> <send_rubbish_here734@hotmail.com> wrote:
>
>> Hello,
>>
>> I am having a problem with a simple script that checks and tells the user
>> what browser they are using.
>>
>> First of all, the browser string for Internet Exploxer contains the text
>> msie and the browser string for a Pocket PC version of internet explorer
>> contain msie AND ppc
>>
>> The problem is that when browsing my test page using pocket pc the script
>> still returns Interent Explorer. My script is below, can anyone tell me
>> how to make it determine correctly when accessing via pocket pc? IT
>> works
>> ok usign using all the other browsers.
>>
>> Thanks,
>>
>> td.
>>
>> http://www.pocketpcheaven.blogspot.com/
>>
>>
>> <?
>> $agent = getenv("HTTP_USER_AGENT");
>>
>> // check to see if running ie
>> if (preg_match("/MSIE/i", "$agent")) {
>> $result = "You are using Microsoft Internet Explorer.";
>> }
>> //check to see if running Firefox
>> else if (preg_match("/Firefox/i", "$agent")) {
>> $result = "You are using Mozilla Firefox.";
>> }
>> // check to see if running opera
>> else if (preg_match("/Opera/i", "$agent")) {
>> $result = "You are using Opera.";
>> }
>> // check to see if running pocket pc browser
>> else if ((preg_match("/PPC/i", "$agent")) && (preg_match("/MSIE/i",
>> "$agent"))) {
>> $result = "You are using Pocket PC Internet Explorer.";
>> }
>> // if anything else just display the browser string
>> else {
>> $result = "You are using $agent";
>> }
>> ?>
>> <HTML>
>> <HEAD>
>> <TITLE>Browser Match Results</TITLE>
>> </HEAD>
>> <BODY>
>> <? echo "<P>$result</P>"; ?>
>> </BODY>
>> </HTML>
>>

>
> Try rearranging your code to check for the presence of PPC first - eg
>
> // check to see if running pocket pc browser
> if ((preg_match("/PPC/i", "$agent")) && (preg_match("/MSIE/i",
> "$agent"))) {
> ...
> // check to see if running ie
> if (preg_match("/MSIE/i", "$agent")) {
> ...



Reply With Quote
  #4 (permalink)  
Old 02-07-2005
Dave Patton
 
Posts: n/a
Default Re: Newbie problems using HTTP_USER_AGENT

"toedipper" <send_rubbish_here734@hotmail.com> wrote in
news:36n8k4F53drr0U1@individual.net:

> Hello,
>
> I am having a problem with a simple script that checks and tells the
> user what browser they are using.


Do you realise that will not be reliable? If you're just
doing it 'for fun', that's OK, but don't count on it providing
accurate results. User Agent strings can easily be spoofed,
and it's also possible that they could be munged(e.g. by
'security software').

--
Dave Patton
Canadian Coordinator, Degree Confluence Project
http://www.confluence.org/
My website: http://members.shaw.ca/davepatton/
Reply With Quote
  #5 (permalink)  
Old 02-08-2005
Good Man
 
Posts: n/a
Default Re: Newbie problems using HTTP_USER_AGENT

"toedipper" <send_rubbish_here734@hotmail.com> wrote in
news:36n8k4F53drr0U1@individual.net:

> Hello,
>
> I am having a problem with a simple script that checks and tells the
> user what browser they are using.


I know you have an answer PHP wise, but this type of thing is best done via
javascript.

In fact, the folks at Mozilla have written a BRILLIANT sniffer that checks
for everything, and can even get beyond browser-spoofing.

http://www.mozilla.org/docs/web-deve...wser_type.html
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

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



All times are GMT +1. The time now is 06:12 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0