Mobile Redirect Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Mobile Redirect Script

    For months, I have been searching for a simple script that can redirect majority of all mobile users to my mobile friendly page. However, I could never seem to find a script that works and especially one that was free. I mean I almost gave up searching until I found someone who had the same problem as I and developed his own script. I guess you could say I was more fortunate than him, since I did not have to deal with the headaches of programming.

    Therefore, for those of you who are like me and want a script that works. I suggest you cut and paste the following php script to your website and simply follow the instructions provided for you below:

    PHP Code:
    <?php

    if(checkmobile()) header("Location:http://www.yourmobilepage.com/");

    function 
    checkmobile(){

    if(
    preg_match("/iphone/i",$_SERVER["HTTP_USER_AGENT"])) return false;

    if(
    preg_match("/Trident/i",$_SERVER["HTTP_USER_AGENT"])) return false;

    if(isset(
    $_SERVER["HTTP_X_WAP_PROFILE"])) return true;

    if(
    preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) return true;

    if(isset(
    $_SERVER["HTTP_USER_AGENT"])){

    if(
    preg_match("/Creative\ AutoUpdate/i",$_SERVER["HTTP_USER_AGENT"])) return false;

    if(
    preg_match("/MSIE/i",$_SERVER["HTTP_USER_AGENT"])) return false;

    $uamatches = array("midp""j2me""avantg""docomo""novarra""palmos""palmsource""240x320""opwv""chtml""pda""windows\ ce""mmp\/""blackberry""mib\/""symbian""wireless""nokia""hand""mobi""phone""cdm""up\.b""audio""SIE\-""SEC\-""samsung""HTC""mot\-""mitsu""sagem""sony""alcatel""lg""erics""vx""NEC""philips""mmm""xx""panasonic""sharp""wap""sch""rover""pocket""benq""java""pt""pg""vox""amoi""bird""compal""kg""voda""sany""kdd""dbt""sendo""sgh""gradi""jb""\d\d\di""moto");

    foreach(
    $uamatches as $uastring){
    if(
    preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"])) return true;
    }

    }
    return 
    false;


    ?>
    Here are 3 basic steps for using this script:

    1. Make certain that the page you are planning to redirect is a .php file.
    2. Copy and paste the script to the top portion of your html code.

    For example:

    <Paste PHP Script Here>
    Code:
    <Paste PHP Script Here>
              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
              "http://www.w3.org/TR/html4/loose.dtd">
              <html>
    3. Under the second line of the PHP script provided above, please replace "http://www.yourmobilepage.com/" with the mobile friendly page you created for your website.

    If you have followed all 3 steps correctly then you have successfully added mobile redirect to your page. Otherwise, you may want to repeat steps 1, 2 and 3. However, if the problem continues you may want to look elsewhere for assistance. Simply for the fact, that my knowledge is very limited on this subject.

    Thank you for understanding and Good luck!
    BakGat
    Code:
    class Counter {
    public:
      void Count();
      int  ReadDisplay();
    private:
      int  CurrentCount;
    };








    Back up my hard drive? How do I put it in reverse?
    My Community
    BakGat
    sigpic

    #2
    wooo its gr8 ...... working 100 %

    Thanks a lot bro !
    JUST JOIN FOR FUN !
    http://wapmaster2.com

    Comment


      #3
      and if you want redirect your web page on other URL then

      <?php

      if(checkmobile()) header("Location:http://yourdomain.com/mobile/index.php");

      function checkmobile(){

      if(preg_match("/iphone/i",$_SERVER["HTTP_USER_AGENT"])) return false;

      if(preg_match("/Trident/i",$_SERVER["HTTP_USER_AGENT"])) return false;

      if(isset($_SERVER["HTTP_X_WAP_PROFILE"])) return true;

      if(preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) return true;

      if(isset($_SERVER["HTTP_USER_AGENT"])){

      if(preg_match("/Creative\ AutoUpdate/i",$_SERVER["HTTP_USER_AGENT"])) return false;

      if(preg_match("/MSIE/i",$_SERVER["HTTP_USER_AGENT"])) return false;

      $uamatches = array("midp", "j2me", "avantg", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto");

      foreach($uamatches as $uastring){
      if(preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"])) return true;
      }

      }
      return false;
      }

      ?>




      <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/WEB/index.html">
      JUST JOIN FOR FUN !
      http://wapmaster2.com

      Comment


        #4
        Or u can Use a mur precise WURFL

        Comment


          #5
          Originally posted by mobileGIGS View Post
          Or u can Use a mur precise WURFL
          This works 100%....
          BakGat
          Code:
          class Counter {
          public:
            void Count();
            int  ReadDisplay();
          private:
            int  CurrentCount;
          };








          Back up my hard drive? How do I put it in reverse?
          My Community
          BakGat
          sigpic

          Comment


            #6
            I dnt tink it cud be as precise as wurfl. WURFL is a project, which means updates, fixes and support, nt 2 mention a up-to-par device database. If u wana hook up a huge or serious project use wurfl, otherwise, if its a lava type site dnt bother wasting ur time, use this one by b0rn2pwn

            Comment


              #7
              This is a simpel and easy 1 HAHA
              BakGat
              Code:
              class Counter {
              public:
                void Count();
                int  ReadDisplay();
              private:
                int  CurrentCount;
              };








              Back up my hard drive? How do I put it in reverse?
              My Community
              BakGat
              sigpic

              Comment


                #8
                RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR]
                RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac| blaz|brew|cell|cldc|cmd-" [NC,OR]
                RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji |leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
                RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
                RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek |qwap|sage|sams|sany" [NC,OR]
                RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
                RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
                RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
                RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|m mp" [NC,OR]
                RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
                RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
                RewriteRule ^(.*)$ http://yourdomainherer.com/index.html [L,R=302]

                it works too ;-)

                Comment

                Working...
                X