HELP - Re-direct based on OS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rich@NeedsHelp.com

    #1

    HELP - Re-direct based on OS

    I am trying to create a site that will re-direct a user based on their OS.

    For this site I will need to send NT4 and 95 users to site A and 2000/XP
    users to site B.
    All others should be directed to site B.

    Thanks in advance.

    Rich
  • chotiwallah

    #2
    Re: HELP - Re-direct based on OS

    navigator.userA gent will deliver some information about the used os

    micha

    Comment

    • alu

      #3
      Re: HELP - Re-direct based on OS

      this should do the job, it actually discriminates between more platforms
      than you require, just delete the unnecessary lines.
      -alu
      _______________ _______________ _______________ ______
      var n = navigator;
      var ua = ' ' + n.userAgent.toL owerCase();

      // find windows platform

      var is_win = ua.indexOf('win ') > 0;
      var is_win16 = (ua.indexOf('16 ') > 0 && ua.indexOf('win ') > 0);
      var is_win31 = is_win16;
      var is_win95 = (ua.indexOf('95 ') > 0 && ua.indexOf('win ') > 0);
      var is_win98 = (ua.indexOf('98 ') > 0 && ua.indexOf('win ') > 0);
      var is_winnt = (ua.indexOf('nt ') > 0 && ua.indexOf('win ') > 0);
      var is_winnt4 = (ua.indexOf('nt 4.0') > 0 && ua.indexOf('win ') > 0);


      // go to yahoo if NT4 or win95, else go to Google

      if(is_winnt4 || is_win95){docum ent.location = "http://www.yahoo.com"}
      else {document.locat ion = "http://www.google.com" }


      _______________ _______________ _______________ _______

      <Rich@NeedsHelp .com> wrote in message news:q_5ge.340$ Ee6.311@fe12.lg a...[color=blue]
      > I am trying to create a site that will re-direct a user based on their OS.
      >
      > For this site I will need to send NT4 and 95 users to site A and 2000/XP
      > users to site B.
      > All others should be directed to site B.
      >
      > Thanks in advance.
      >
      > Rich[/color]


      Comment

      • Richard Cornford

        #4
        Re: HELP - Re-direct based on OS

        alu wrote:[color=blue]
        > this should do the job, it actually discriminates between more
        > platforms than you require, just delete the unnecessary lines.
        > -alu
        > _______________ _______________ _______________ ______
        > var n = navigator;
        > var ua = ' ' + n.userAgent.toL owerCase();
        >
        > // find windows platform
        >
        > var is_win = ua.indexOf('win ') > 0;[/color]
        <snip>[color=blue]
        > var is_winnt4 = (ua.indexOf('nt 4.0') > 0 && ua.indexOf('win ') > 0);[/color]
        <snip>

        This appears to be based on the assumption that the userAgent property
        of a browser's navigator object represents an accurate source of
        information about the operating system on which the browser is running.
        That assumption simply is not true.

        Richard.


        Comment

        • Randy Webb

          #5
          Re: HELP - Re-direct based on OS

          Rich@NeedsHelp. com wrote:[color=blue]
          > I am trying to create a site that will re-direct a user based on their OS.
          >
          > For this site I will need to send NT4 and 95 users to site A and 2000/XP
          > users to site B.
          > All others should be directed to site B.[/color]

          <a href="siteA.htm l">NT4 and Win95 Users</a>
          <a href="siteB.htm l">All other Users</a>

          Anything else will fail.
          [color=blue]
          > Thanks in advance.[/color]

          Welcome.

          --
          Randy
          comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

          Comment

          • alu

            #6
            Re: HELP - Re-direct based on OS

            Richard, I'm curious why that is - do some browsers disguise the platform,
            or is userAgent not universal?
            thanks
            -alu


            "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message
            news:d5r93g$ejh $1$8300dec7@new s.demon.co.uk.. .[color=blue]
            > alu wrote:[color=green]
            > > this should do the job, it actually discriminates between more
            > > platforms than you require, just delete the unnecessary lines.
            > > -alu
            > > _______________ _______________ _______________ ______
            > > var n = navigator;
            > > var ua = ' ' + n.userAgent.toL owerCase();
            > >
            > > // find windows platform
            > >
            > > var is_win = ua.indexOf('win ') > 0;[/color]
            > <snip>[color=green]
            > > var is_winnt4 = (ua.indexOf('nt 4.0') > 0 && ua.indexOf('win ') > 0);[/color]
            > <snip>
            >
            > This appears to be based on the assumption that the userAgent property
            > of a browser's navigator object represents an accurate source of
            > information about the operating system on which the browser is running.
            > That assumption simply is not true.
            >
            > Richard.
            >
            >[/color]


            Comment

            • Richard Cornford

              #7
              Re: HELP - Re-direct based on OS

              alu wrote:[color=blue]
              > Richard, I'm curious why that is - do some browsers
              > disguise the platform, or is userAgent not universal?[/color]
              <snip>

              The navigator.usetA gent property reflects the HTTP User Agent header.
              That header is not subject to any stringent specifications as to its
              contents and many browsers take the freedom that the HTTP specification
              gives them as an opportunity to use completely fictitious User Agent
              headers. And in addition to browsers that use fictitious User Agent
              headers by default, I don't know of any browser where the User Agent
              header is not user configurable to take any form the user chooses.

              As a result no accurate information can be derived from the User Agent
              header or the navigator.userA gent property (no matter how many people
              don't know enough about the subject to be suggesting otherwise).

              Richard.


              Comment

              • Matt Kruse

                #8
                Re: HELP - Re-direct based on OS

                Richard Cornford wrote:[color=blue]
                > As a result no accurate information can be derived from the User Agent
                > header or the navigator.userA gent property (no matter how many people
                > don't know enough about the subject to be suggesting otherwise).[/color]

                If a user agent purposely supplies incorrect information, then the user of
                that user agent should expect to get incorrect results.

                If a browser supplies a meaningless or simplified User-Agent header, that's
                one thing. If it masquerades as another browser, then it should expect to
                experience quirks associated with that. If it knowingly supplies incorrect
                information, then users should expect to see results consistent with that
                incorrect information.

                In much the same way, if a browser reported that document.getEle mentById was
                available, but then failed when it was used, the script author couldn't be
                held responsible for this. The browser supplied erroneous information.

                There are a lot of things that could stop working correctly if browsers
                decided to report incorrect information for the hell of it. What if the
                browser reported that it could accept a certain type of response, but then
                died when it was delivered? Would you say "don't trust the Accept header,
                since browsers may report it incorrectly"?

                Developers should never assume anything to be correct when dealing with
                security and data integrity, or when collecting statistics. However, if the
                browser reports its operating system to the server, and the server delivers
                content customized for that operating system, and the content is incorrect,
                then I fault the browser/user, not the developer.

                From the HTTP Specs:

                User-Agent:
                This line if present gives the software program used by the original client.
                This is for statistical purposes and the tracing of protocol violations. It
                should be included. The first white space delimited word must be the
                software product name, with an optional slash and version designator. Other
                products which form part of the user agent may be put as separate words.

                It doesn't say "fake this if you want to, therefore making this header
                meaningless." If a browser reports an incorrect user agent string, then it
                violates the very first sentence.

                --
                Matt Kruse



                Comment

                • RobG

                  #9
                  Re: HELP - Re-direct based on OS

                  Matt Kruse wrote:[color=blue]
                  > Richard Cornford wrote:
                  >[color=green]
                  >>As a result no accurate information can be derived from the User Agent
                  >>header or the navigator.userA gent property (no matter how many people
                  >>don't know enough about the subject to be suggesting otherwise).[/color]
                  >
                  >
                  > If a user agent purposely supplies incorrect information, then the user of
                  > that user agent should expect to get incorrect results.[/color]

                  I can understand your argument Matt, but user agent and OS information
                  continues to be used to discriminate against visitors for totally
                  spurious reasons.

                  As a result, many 'minority' browsers can only get access to sites by
                  pretending to be what they aren't.

                  In that context, browser creators will continue to provide the
                  functionality for user agents to masquerade as whatever the user wants,
                  and therefore any assumption that a browser is what the user agent says
                  it is is likely to be wrong a significant proportion of the time.

                  [...][color=blue]
                  > It doesn't say "fake this if you want to, therefore making this header
                  > meaningless." If a browser reports an incorrect user agent string, then it
                  > violates the very first sentence.
                  >[/color]

                  The downside of violating the specification for user agent string is
                  what? Messing up someone's stats?

                  The downside of strictly implementing the spec is being refused entry
                  to sites purely because you are using a UA other than one that the site
                  developer wishes you to use.

                  In the context of the 'browser wars' and wider scope of desktop OS
                  market share, the penalty for strict adherence was far greater than
                  any that could be derived from allowing users to set their own UA
                  string.

                  But having said all that, I think most new browsers do provide an
                  honest UA string by default (though many browser/OS sniffers to a
                  pretty crap job of interpreting them).

                  The OP is probably best to have something like "I think you are using
                  <insert reported OS here>, please follow <OS specific link>" and
                  provide alternatives in case it is incorrect.

                  --
                  Rob

                  Comment

                  • Matt Kruse

                    #10
                    Re: HELP - Re-direct based on OS

                    RobG wrote:[color=blue]
                    > I can understand your argument Matt, but user agent and OS
                    > information continues to be used to discriminate against visitors
                    > for totally spurious reasons.[/color]

                    I agree that this does happen sometimes, and it's a bad practice. I can
                    understand a browser masquerading as another more popular browser, but I
                    don't see why the OS should be faked. It could just be left blank.
                    [color=blue]
                    > The downside of violating the specification for user agent string is
                    > what? Messing up someone's stats?[/color]

                    The downside could be that you receive content that doesn't apply to you.

                    For example, I worked on a company's intranet that did extensive browser
                    sniffing upon login. If it found that you were using a browser that needed
                    patches or updates, it gave you a direct link to the file on the fileserver
                    to get you updated. If your browser faked its UA header, you might be given
                    the wrong update file.

                    Of course, this was an intranet and a slightly different case, but it's an
                    example of when the user might get incorrect content because their browser
                    supplies incorrect information.
                    [color=blue]
                    > The downside of strictly implementing the spec is being refused entry
                    > to sites purely because you are using a UA other than one that the
                    > site developer wishes you to use.[/color]

                    Granted, from the user point of view it's a tough call sometimes.
                    [color=blue]
                    > The OP is probably best to have something like "I think you are using
                    > <insert reported OS here>, please follow <OS specific link>" and
                    > provide alternatives in case it is incorrect.[/color]

                    I agree with you there - use the UA string to provide a logical default
                    action, but always supply the user with other options in case your
                    assumptions based on UA are incorrect.

                    --
                    Matt Kruse



                    Comment

                    • Richard Cornford

                      #11
                      Re: HELP - Re-direct based on OS

                      Matt Kruse wrote:[color=blue]
                      > Richard Cornford wrote:[color=green]
                      >> As a result no accurate information can be derived from
                      >> the User Agent header or the navigator.userA gent property
                      >> (no matter how many people don't know enough about the
                      >> subject to be suggesting otherwise).[/color]
                      >
                      > If a user agent purposely supplies incorrect information,
                      > then the user of that user agent should expect to get
                      > incorrect results.[/color]

                      Information can only be incorrect where there is some means of
                      determining what correct information would be. All you are complaining
                      about here is information that is inconvenient to you, and it is
                      inconvenient to you because you have made an invalid assumption about
                      how meaningful that information is supposed to be.
                      [color=blue]
                      > If a browser supplies a meaningless or simplified
                      > User-Agent header, that's one thing. If it masquerades
                      > as another browser, then it should expect to experience
                      > quirks associated with that.[/color]

                      It is always worth remembering that UA spoofing was started by Microsoft
                      and if they had not done so it may have been possible for the HTTP 1.1
                      spec to make some sort of strong requirement about the contents of the
                      header. As it is any consequences that follow from the sending of
                      User-Agent headers are the fault of anyone interested in those headers,
                      as they are labouring under an invalid assumption. The other browser
                      manufacturers cannot be considered at fault for following Microsoft,
                      motivated by exactly what motivated Microsoft to spoof Netscape in the
                      first place.
                      [color=blue]
                      > If it knowingly supplies
                      > incorrect information, then users should expect to
                      > see results consistent with that incorrect information.[/color]

                      Assuming a user with expectations related to the correct operation of
                      HTTP 1.1, it is not unreasonable to expect behaviour that conforms with
                      the standard for the protocol.
                      [color=blue]
                      > In much the same way, if a browser reported that
                      > document.getEle mentById was available, but then failed when
                      > it was used, the script author couldn't be held responsible for
                      > this. The browser supplied erroneous information.[/color]

                      That would be a different situation. If the application of ECMAScript
                      operators and specified processes produced erroneous results when
                      applied to a DOM member than the browser's ECMAScript implementation
                      would not be a conforming ECMAScript implementation.

                      But the only significant failure of - document.getEle mentById -, in an
                      environment where feature detection verified the method's existence,
                      would be to throw on exception when called, which is objectively a
                      violation of the W3C Core DOM specification.
                      [color=blue]
                      > There are a lot of things that could stop working correctly if
                      > browsers decided to report incorrect information for the hell of it.[/color]

                      But we are not talking about incorrect information where the User-Agent
                      header is concerned because there is no standard for correct
                      information.
                      [color=blue]
                      > What if the browser reported that it could accept a
                      > certain type of response,[/color]

                      Like IE claming to accept *.*?
                      [color=blue]
                      > but then died when it was delivered?[/color]

                      IE handles the content types it asserts its acceptance of, but cannot
                      directly handle, by downloading them to disc. (does that qualify as
                      dying?)
                      [color=blue]
                      > Would you say "don't trust the Accept header,[/color]

                      I would recommend a big pinch of salt when presented with *.*.
                      [color=blue]
                      > since browsers may report it incorrectly"?[/color]

                      Some do. But the contents of Accept headers are well specified so they
                      are not equivalent situations. An Accept header may be objectively
                      malformed, but a User-Agent header cannot be.

                      <snip>[color=blue]
                      > However, if the browser reports its operating system
                      > to the server,[/color]

                      Is the browser reporting its operating system to the server? Or is it
                      just sending a sequence of characters that should never have been
                      expected to convey meaning, and particularly not information (and
                      specifically not OS information)?
                      [color=blue]
                      > and the server delivers content customized for that
                      > operating system,[/color]

                      Exactly what content needs customising to an operating system? Spyware?
                      viruses? Certainly not HTML, CSS, browser scripts, images, sound, flash,
                      video or Java applets.
                      [color=blue]
                      > and the content is incorrect, then I fault the browser/user,
                      > not the developer.[/color]

                      No it is the fault of the developer for mistaking a meaningless sequence
                      of characters for a source of information.
                      [color=blue]
                      > From the HTTP Specs:[/color]

                      But which spec, you really should cite your sources.
                      [color=blue]
                      > User-Agent:
                      > This line if present gives the software program used by the
                      > original client. This is for statistical purposes and the
                      > tracing of protocol violations. It should be included. The
                      > first white space delimited word must be the software product
                      > name, with an optional slash and version designator. Other
                      > products which form part of the user agent may be put as
                      > separate words.[/color]

                      So does this say anything about OS 'information'?

                      I assume this is from the HTTP 1.0 spec, the one Microsoft violated, and
                      continue to violate as the 'first white space delimited word' in their
                      default UA header is someone else's product name. So how many browsers
                      are there that send information that is 'correct' by HTTP 1.0? One;
                      Mozilla/Netscape/Gecko.

                      But moving up to date and looking at the HTTP 1.1 specification, and
                      starting with the official interpretation of the spec, we find:-

                      <quote cite="RFC 2616 Hypertext Transfer Protocol - HTTP/1.1">
                      1.2 Requirements

                      The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
                      "SHOULD", "SHOULD NOT", "RECOMMENDE D", "MAY", and "OPTIONAL" in this
                      document are to be interpreted as described in RFC 2119 [34].

                      An implementation is not compliant if it fails to satisfy one or more
                      of the MUST or REQUIRED level requirements for the protocols it
                      implements. An implementation that satisfies all the MUST or REQUIRED
                      level and all the SHOULD level requirements for its protocols is said
                      to be "unconditionall y compliant"; one that satisfies all the MUST
                      level requirements but not all the SHOULD level requirements for its
                      protocols is said to be "conditiona lly compliant."
                      </quote>

                      Which give us a list of significant key words to be used in interpreting
                      the specification, and particularly the User-Agent header section:-

                      <quote cite="RFC 2616 Hypertext Transfer Protocol - HTTP/1.1">
                      14.43 User-Agent

                      The User-Agent request-header field contains information about the
                      user agent originating the request. This is for statistical purposes,
                      the tracing of protocol violations, and automated recognition of user
                      agents for the sake of tailoring responses to avoid particular user
                      agent limitations. User agents SHOULD include this field with
                      requests. The field can contain multiple product tokens (section 3.8)
                      and comments identifying the agent and any subproducts which form a
                      significant part of the user agent. By convention, the product tokens
                      are listed in order of their significance for identifying the
                      application.
                      </quote>

                      - Where we find one occurrence of a key word. The word SHOULD in "User
                      agents SHOULD include this field with requests", and we know of no user
                      agents that do not send this filed with their requests so our formal
                      specification is satisfied.

                      When it comes to the contents of the header we find that the operative
                      word is "can"; "The field can contain ...". Not MUST, not even SHOULD,
                      but "can". It is not a key word in the specification and can only
                      reasonably be interpreted as a suggestion, the following of which is
                      completely optional.

                      The bottom line is that by the HTTP 1.1 specification the contents of
                      the User-Agent header are entirely at the discretion of the author of
                      the sending software. That software may send anything (so long as it
                      sends something) and be "unconditionall y compliant" with HTTP 1.1.

                      If web developers fail to comprehend this, and make assumptions and
                      deductions based on the contents of the User-Agent header that is an
                      error on their part, and they are personally responsible for the
                      consequences of that error.
                      [color=blue]
                      > It doesn't say "fake this if you want to,[/color]

                      That is what the HTTP 1.1 specification does say (by placing no barrier
                      to doing precisely that).
                      [color=blue]
                      > therefore making this header meaningless."
                      > If a browser reports an incorrect user agent string,
                      > then it violates the very first sentence.[/color]

                      Even disregarding the current specification, where does it get you to
                      declare that the most common browser in use (IE) violates a
                      specification and sends 'incorrect information'? You still have
                      absolutely no realistic expectation of the User-Agent header containing
                      'correct information', and the HTTP 1.1 specification makes it explicit
                      that no such expectation should exist (which represents a useful
                      clarification of the position).

                      Richard.


                      Comment

                      • Richard Cornford

                        #12
                        Re: HELP - Re-direct based on OS

                        RobG wrote:[color=blue]
                        > Matt Kruse wrote:[/color]
                        <snip>[color=blue]
                        > [...][color=green]
                        >> It doesn't say "fake this if you want to, therefore making
                        >> this header meaningless." If a browser reports an incorrect
                        >> user agent string, then it violates the very first sentence.[/color]
                        >
                        > The downside of violating the specification for user agent
                        > string is what? Messing up someone's stats?[/color]

                        Matt is being disingenuous in not citing which specification he was
                        quoting, the User-Agent header is not capable of violating the current
                        HTTP specification, as there is nothing to violate.

                        <snip>[color=blue]
                        > ... , I think most new browsers do provide an
                        > honest UA string by default (though many browser/OS
                        > sniffers to a pretty crap job of interpreting them).[/color]
                        <snip>

                        You really need to expose yourself to some more web browsers. I would
                        say that the majority of recent web browsers spoof IE's UA string by
                        default. I can't think of many PDA/Embedded browsers that do not (and
                        the majority of recently released browsers have been PDA/Embedded
                        browsers, as the rise of advanced mobile phones, etc, make that the
                        growing (and profitable) market).

                        Richard.


                        Comment

                        • Matt Kruse

                          #13
                          Re: HELP - Re-direct based on OS

                          Richard Cornford wrote:[color=blue]
                          > Is the browser reporting its operating system to the server? Or is it
                          > just sending a sequence of characters that should never have been
                          > expected to convey meaning, and particularly not information (and
                          > specifically not OS information)?[/color]

                          Is "you're being obtuse" just a sequence of characters, or does it
                          intentionally convey meaning? If you take it as a statement of opinion about
                          your post, are you reading more into it than can be reliably determined?

                          The UA string has become a convention, a "de-facto standard". Not every
                          browser follows it, nor is any browser required to follow it. However, when
                          a browser _does_ follow the convention, and intentionally supplies erroneous
                          information, then a user of such a browser should expect to see results
                          consistent with what the browser reports.

                          A developer should never rely on this information as being correct. However,
                          making default decisions or guiding a user to the most appropriate
                          information based on what their browser reported certainly makes sense. As
                          long as there is an alternate path for the user in case the information
                          reported by the browser is not correct.

                          --
                          Matt Kruse



                          Comment

                          • Rich@NeedsHelp.com

                            #14
                            Re: HELP - Re-direct based on OS

                            I guess I should have stated that the webpage will be hosted on a corporate
                            intranet where the standard image is Microsoft IE 5.5 v2 or higher. Other
                            browsers are not supported.

                            Comment

                            • Richard Cornford

                              #15
                              Re: HELP - Re-direct based on OS

                              Matt Kruse wrote:[color=blue]
                              > Richard Cornford wrote:[color=green]
                              >> Is the browser reporting its operating system to the
                              >> server? Or is it just sending a sequence of characters
                              >> that should never have been expected to convey meaning,
                              >> and particularly not information (and specifically not
                              >> OS information)?[/color]
                              >
                              > Is "you're being obtuse" just a sequence of characters,
                              > or does it intentionally convey meaning?[/color]

                              I don't know, is it a sentence in the English language or the contents
                              of an HTTP 1.1 User-Agent header?
                              [color=blue]
                              > If you take it as a statement of opinion about
                              > your post, are you reading more into it than can be
                              > reliably determined?[/color]

                              It is ambiguous in the form presented.
                              [color=blue]
                              > The UA string has become a convention, a "de-facto standard".[/color]

                              I wouldn't argue with that. There is a de-facto standard, and Microsoft
                              established it, but it isn't the standard you think it is. The de-facto
                              standard for User-Agent headers is that whenever it is expedient to
                              place fictitious content in a User-Agent header it is acceptable to do
                              so. That describes the reality of the situation (currently and
                              historically).
                              [color=blue]
                              > Not every browser
                              > follows it, nor is any browser required to follow it.
                              > However, when a browser _does_ follow the convention, and
                              > intentionally supplies erroneous information,[/color]

                              How can a browser both follow your de-facto standard and supply
                              erroneous information? All you are saying here is that you have an
                              expectation that a lie will take a form from which you can extract a
                              truth. But if that was a realistic expectation there would be no point
                              in telling lies in the first place.
                              [color=blue]
                              > then a user of such a browser should expect to
                              > see results consistent with what the browser reports.[/color]

                              Why? The software receiving the User-Agent header has no reason to
                              deduce anything from that header (except that there is a user agent
                              making the request). There is no reason to expect the contents of the
                              header to make any difference to anything.

                              And if web developers want to disregard the HTTP 1.1 specification, and
                              ignore the normal, common and long established practice of browser
                              manufacturers (including Microsoft) then they are personally responsible
                              for the consequences of taking such an incompetent attitude. Not the
                              browsers, who are being "unconditionall y compliant" with the spec, and
                              not the users of those "unconditionall y compliant" browsers; the web
                              developers are at fault.
                              [color=blue]
                              > A developer should never rely on this information as
                              > being correct.[/color]

                              The developer should not expect the 'information' to be meaningful.
                              [color=blue]
                              > However, making default decisions or guiding a user to
                              > the most appropriate information based on what their
                              > browser reported certainly makes sense.[/color]

                              Less sense than creating an interoperable system where the nature of the
                              user agent doesn't matter at all.
                              [color=blue]
                              > As long as there is an alternate path for the user in case
                              > the information reported by the browser is not correct.[/color]

                              So that is a process of writing code to make deductions from meaningless
                              User-Agent header content, expending clock cycles running that code,
                              showing the user the results of that deduction (and looking foolish
                              whenever they are wrong) and then providing an interoperable alternative
                              to cover the inevitable shortcomings in the first stage?

                              As opposed to recognising that the nature of the user agent on the
                              public Internet is (and always will be) unknowable and writing one
                              interoperable system (with the technologies that have been designed to
                              be interoperable form the outset).

                              Richard.


                              Comment

                              Working...