how to detect page request is from mobile or PC?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dhillarun
    New Member
    • Mar 2007
    • 18

    #1

    how to detect page request is from mobile or PC?

    Hi Everybody,

    I have developed a website using PHP, which will produce HTML code.

    But I have some pages in PHP ,which will produce WML code for mobile browsers.

    I want to redirect to WML page,if the site is accessed from the mobile. Otherwise it should display HTML page if the site is accessed from Desktop PC.

    Please do reply me.

    Arun.
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    I think you could use a simple javascript code to detect the client
    (run a Google search for "javascript browser detection")
    and redirect accordingly.

    Comment

    • dhillarun
      New Member
      • Mar 2007
      • 18

      #3
      Originally posted by michaelb
      I think you could use a simple javascript code to detect the client
      (run a Google search for "javascript browser detection")
      and redirect accordingly.
      As the javascript is running in the client side,some mobile browsers will not support "Javascript ". So I want to achieve the same in the server side itself.

      (i.e) In the server, I want to know which device (whether mobile or Desktop Computer) is acessing the website.

      If the device accessing the website is a mobile or PDA , then it should redirect into a PHP page which will produce WML code.

      Otherwise if the request is from computer, then it should redirect into a PHP page which will produce HTML code.

      Comment

      • michaelb
        Recognized Expert Contributor
        • Nov 2006
        • 534

        #4
        >> ... some mobile browsers will not support "Javascript ".
        Sorry, I overlooked this.

        Back to the server code, when you use a mobile device is $_SERVER['HTTP_USER_AGEN T'] gets some meaningful value?

        Comment

        • joshe766
          New Member
          • Jun 2007
          • 2

          #5
          Originally posted by dhillarun
          Hi Everybody,

          I have developed a website using PHP, which will produce HTML code.

          But I have some pages in PHP ,which will produce WML code for mobile browsers.

          I want to redirect to WML page,if the site is accessed from the mobile. Otherwise it should display HTML page if the site is accessed from Desktop PC.

          Please do reply me.

          Arun.




          this is the script....this is s php type...





          <?php
          /////////////////////////////////////////////////////////////////////////////
          ///*************** *************** *************** *************** ******///////
          ///*PROYECTO WAP CONSULTA DE NOTAS-CORPORACION UNIVERSITARIA DE CIENCIA*////
          ///*Y DESARROLLO UNICIENCIA-EXTENSION BUCARAMANGA.*** *************** ***////
          ///*TESIS PRESENTADA POR: JOSE ALVAREZ VERGARA-INGENIERIA INFORMATICA*////
          ///*************** *************** *************** *************** ********//
          ////////////////////////////////////////////////////////////////////////

          //PROTECCION DE NAVEGADOR
          $user = explode ('/', $HTTP_USER_AGEN T);
          //EL ACCESO ESTA DENEGADO PARA CUALQUIERA DE ESTOS NAVEGADORES Y SERA REDIRECCIONADO A LA PAGINA PRINCIPAL DE LA U
          if($user[0]=="Opera"||$use r[0]=="Mozilla"||$u ser[0]=="Go!Zilla"||$ user[0]=="Netscape"||$ user[0]=="MSIE"){
          //PAGINA COMPATIBLE A LA CUAL SE REDIRECCIONA
          header ('Location: http://www.unicienciab ga.edu.co/wap/error.php');}

          //EN CASO QUE SEA UN NAVEGADOR WAP COMPATIBLE SE PERMITIRÁ EL ACCESO
          include("parame tros.inc");
          ?>

          <wml>
          <card ontimer='inicio .wml#main' title='<? echo $SITENAME; ?>'>
          <timer value="50"/>
          <p align='center'>
          <small> SISTEMA WAP<br/>
          <strong>Unicien cia Bucaramanga</strong></small><br/>

          <img src="./images/uniciencia.jpg" alt="Uniciencia "/><br/>

          <small>Educacio n Integral de Optima Calidad</small><br/>
          <small><a href='inicio.wm l#main'>Ingresa r</a></small>
          </p>

          </card>
          </wml>

          Comment

          Working...