HTTP_BROWSER_AGENT on pocketpc

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • toedipper

    HTTP_BROWSER_AGENT on pocketpc

    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.

    Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.



    <?
    $agent = getenv("HTTP_US ER_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>Browse r Match Results</TITLE>
    </HEAD>
    <BODY>
    <? echo "<P>$result </P>"; ?>
    </BODY>
    </HTML>



  • G-man

    #2
    Re: HTTP_BROWSER_AG ENT on pocketpc


    "toedipper" <send_rubbish_h ere734@hotmail. com> wrote in message
    news:36mtd8F4uq 6rdU1@individua l.net...[color=blue]
    > Hello,[/color]

    Hi.
    [color=blue]
    > 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.[/color]

    The problem is because $agent contains MSIE, the first IF statement citeria
    is being met. You are ELSE IF'ing the rest of the way down the script.
    Because the first IF statement was met, it won't run anymore IF's. Therefore
    I recommend you remove the ELSE's and just run independant IF's.

    Ta,
    G.


    Comment

    • toedipper

      #3
      Re: HTTP_BROWSER_AG ENT on pocketpc

      Cheers.

      I see what you mean but the browser string for IE also contains the word
      Mozilla and that doesn't trip up.

      td.


      "G-man" <testbox@silent reply.co.uk> wrote in message
      news:YmrNd.8853 $8B3.3617@text. news.blueyonder .co.uk...[color=blue]
      >
      > "toedipper" <send_rubbish_h ere734@hotmail. com> wrote in message
      > news:36mtd8F4uq 6rdU1@individua l.net...[color=green]
      >> Hello,[/color]
      >
      > Hi.
      >[color=green]
      >> 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.[/color]
      >
      > The problem is because $agent contains MSIE, the first IF statement
      > citeria is being met. You are ELSE IF'ing the rest of the way down the
      > script. Because the first IF statement was met, it won't run anymore IF's.
      > Therefore I recommend you remove the ELSE's and just run independant IF's.
      >
      > Ta,
      > G.
      >[/color]


      Comment

      • Janwillem Borleffs

        #4
        Re: HTTP_BROWSER_AG ENT on pocketpc

        toedipper wrote:[color=blue]
        > I see what you mean but the browser string for IE also contains the
        > word Mozilla and that doesn't trip up.
        >[/color]

        That's because you aren't matching for "Mozilla". What G-man means, is that
        you should check for powerpc before IE or make the check for IE less
        general:

        // check to see if running ie
        if (preg_match("/MSIE/i", "$agent") && !preg_match("/PPC/i", "$agent")) {
        $result = "You are using Microsoft Internet Explorer.";
        }


        JW



        Comment

        • Janwillem Borleffs

          #5
          Re: HTTP_BROWSER_AG ENT on pocketpc

          Janwillem Borleffs wrote:[color=blue]
          > // check to see if running ie
          > if (preg_match("/MSIE/i", "$agent") && !preg_match("/PPC/i",
          > "$agent")) { $result = "You are using Microsoft Internet
          > Explorer."; }
          >[/color]

          Coming to think of it, this will also match Opera in MSIE spoofing mode...

          The following might work out better (emphasis on "might", because browser
          detection based upon the user agent string is always error prone):

          if (preg_match("/MSIE/i", $agent) &&
          !preg_match("/PPC/i", $agent) &&
          !preg_match("/Opera/i", $agent)) {
          $result = "You are using Microsoft Internet Explorer.";
          }


          JW



          Comment

          Working...