Send out different content depends on User Agent String

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allerdyce.John@gmail.com

    Send out different content depends on User Agent String

    Hi,

    Is there an easy way in PHP which send outs different content depends
    on User Agent String value?
    If yes, is there an example/documentation?

    Thank you.

  • Sune Storgaard

    #2
    Re: Send out different content depends on User Agent String

    Allerdyce.John@ gmail.com wrote:[color=blue]
    > Hi,
    >
    > Is there an easy way in PHP which send outs different content depends
    > on User Agent String value?
    > If yes, is there an example/documentation?[/color]

    Im not sure what exactly you want to achieve, but this reserved variable
    will contain the useragent string (which can be forged easely)

    $_SERVER['HTTP_USER_AGEN T']

    It will return something like this:
    "Mozilla/5.0 (Windows; U; Windows NT 5.1; da; rv:1.8) Gecko/20051111
    Firefox/1.5"Use some str function to check for occurences of "mozilla" and
    do some conditional code based on result ?A little untested
    example:<?php$o uragent = $_SERVER['HTTP_USER_AGEN T']; // could be fitted
    into the IF sentence if (substr_count($ ouragent,"Mozil la")!=0) {
    echo "Mozilla..maybe ";}else{ echo "some other stuff"}?>


    Comment

    • NC

      #3
      Re: Send out different content depends on User Agent String

      Allerdyce.John@ gmail.com wrote:[color=blue]
      >
      > Is there an easy way in PHP which send outs different content
      > depends on User Agent String value?[/color]

      Yes. There is a superglobal variable $_SERVER['HTTP_USER_AGEN T']
      [color=blue]
      > If yes, is there an example/documentation?[/color]

      Here is the documentation on the subject in its entirety:

      'HTTP_USER_AGEN T'
      Contents of the User-Agent: header from the current request,
      if there is one. This is a string denoting the user agent being
      which is accessing the page. A typical example is: Mozilla/4.5
      [en] (X11; U; Linux 2.2.9 i586). Among other things, you can
      use this value with get_browser() to tailor your page's output
      to the capabilities of the user agent.

      Source:


      Cheers,
      NC

      Comment

      • d

        #4
        Re: Send out different content depends on User Agent String


        <Allerdyce.John @gmail.com> wrote in message
        news:1138340794 .511698.285410@ g44g2000cwa.goo glegroups.com.. .[color=blue]
        > Hi,
        >
        > Is there an easy way in PHP which send outs different content depends
        > on User Agent String value?
        > If yes, is there an example/documentation?[/color]

        Be aware that the user agent string can be changed, and therefor isn't as
        accurate as detecting the browser using javascript (but, on the other hand,
        is completely transparent)
        [color=blue]
        > Thank you.
        >[/color]

        dave


        Comment

        Working...