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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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> |
|
|||
|
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")) { ... |
|
|||
|
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")) { > ... |
|
|||
|
"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/ |
|
|||
|
"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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|