mobile redirect code

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

    mobile redirect code

    PHP Code:
    <?php
    //compliments of http://www.buchfelder.biz/

    $mobile "http://mobile.fantasyonline.us/";
    $text $_SERVER['HTTP_USER_AGENT'];
    $var[0] = 'Mozilla/4.';
    $var[1] = 'Mozilla/3.0';
    $var[2] = 'AvantGo';
    $var[3] = 'ProxiNet';
    $var[4] = 'Danger hiptop 1.0';
    $var[5] = 'DoCoMo/';
    $var[6] = 'Google CHTML Proxy/';
    $var[7] = 'UP.Browser/';
    $var[8] = 'SEMC-Browser/';
    $var[9] = 'J-PHONE/';
    $var[10] = 'PDXGW/';
    $var[11] = 'ASTEL/';
    $var[12] = 'Mozilla/1.22';
    $var[13] = 'Handspring';
    $var[14] = 'Windows CE';
    $var[15] = 'PPC';
    $var[16] = 'Mozilla/2.0';
    $var[17] = 'Blazer/';
    $var[18] = 'Palm';
    $var[19] = 'WebPro/';
    $var[20] = 'EPOC32-WTL/';
    $var[21] = 'Tungsten';
    $var[22] = 'Netfront/';
    $var[23] = 'Mobile Content Viewer/';
    $var[24] = 'PDA';
    $var[25] = 'MMP/2.0';
    $var[26] = 'Embedix/';
    $var[27] = 'Qtopia/';
    $var[28] = 'Xiino/';
    $var[29] = 'BlackBerry';
    $var[30] = 'Gecko/20031007';
    $var[31] = 'MOT-';
    $var[32] = 'UP.Link/';
    $var[33] = 'Smartphone';
    $var[34] = 'portalmmm/';
    $var[35] = 'Nokia';
    $var[36] = 'Symbian';
    $var[37] = 'AppleWebKit/413';
    $var[38] = 'UPG1 UP/';
    $var[39] = 'RegKing';
    $var[40] = 'STNC-WTL/';
    $var[41] = 'J2ME';
    $var[42] = 'Opera Mini/';
    $var[43] = 'SEC-';
    $var[44] = 'ReqwirelessWeb/';
    $var[45] = 'AU-MIC/';
    $var[46] = 'Sharp';
    $var[47] = 'SIE-';
    $var[48] = 'SonyEricsson';
    $var[49] = 'Elaine/';
    $var[50] = 'SAMSUNG-';
    $var[51] = 'Panasonic';
    $var[52] = 'Siemens';
    $var[53] = 'Sony';
    $var[54] = 'Verizon';
    $var[55] = 'Cingular';
    $var[56] = 'Sprint';
    $var[57] = 'AT&T';
    $var[58] = 'Nextel';
    $var[59] = 'Pocket PC';
    $var[60] = 'T-Mobile';    
    $var[61] = 'Orange';
    $var[62] = 'Casio';
    $var[63] = 'HTC';
    $var[64] = 'Motorola';
    $var[65] = 'Samsung';
    $var[66] = 'NEC';

    $result count($var);

    for (
    $i=0;$i<$result;$i++)
    {    
        
    $ausg stristr($text$var[$i]);    
        if(
    strlen($ausg)>0)
        {
            
    header("location: $mobile");
            echo 
    '<BR>Mobile device detected ... <BR>';
            break;
        }
        
    }
    ?>
    for some reason it redirecting ie to mobile

    #2
    remove $var[14] = 'Windows CE';

    Comment


      #3
      try this
      PHP Code:
      <?php
      $mobile_browser 
      '0';
       
      if(
      preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i'strtolower($_SERVER['HTTP_USER_AGENT']))) {
          
      $mobile_browser++;
      }
       
      if((
      strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {
          
      $mobile_browser++;
      }    
       
      $mobile_ua strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
      $mobile_agents = array(
          
      'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
          
      'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
          
      'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
          
      'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
          
      'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
          
      'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
          
      'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
          
      'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
          
      'wapr','webc','winw','winw','xda','xda-');
       
      if(
      in_array($mobile_ua,$mobile_agents)) {
          
      $mobile_browser++;
      }
       
      if (
      strpos(strtolower($_SERVER['ALL_HTTP']),'operamini')>0) {
          
      $mobile_browser++;
      }
       
      if (
      strpos(strtolower($_SERVER['HTTP_USER_AGENT']),' ppc;')>0) {
          
      $mobile_browser++;
      }
       
      if (
      strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows ce')>0) {
          
      $mobile_browser++;
      }
      if (
      strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
          
      $mobile_browser=0;
      }
       
      if (
      strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'iemobile')>0) {
          
      $mobile_browser++;
      }
       
      if(
      $mobile_browser>0) {
      header('Location:http://mobilesite.com');
      }
      else {
      header('Location:http://Internetexplorersite.com');
      }
      ?>

      Comment


        #4
        I just tested anshul's code and it's working nice.
        Wait...
        sigpic

        Comment


          #5
          Apache Mobile Filter

          I suggest to use the "Apache Mobile Fillter".

          The Apache Mobile Filter allows you to access WURFL from any programming language, not just Java and php that is traditionally used for dynamic mobile web sites.

          The module detects the mobile device and passes the WURFL capabilities on to the other web application as environment variables. It can also be used to resize images on the fly to adapt to the screen size of the mobile device.
          Try it and let me know your opinion.

          For more info: Apache Mobile Filter 2.0

          I have made two test pages:

          PC Test Page: http://apachemobilefilter.nogoogle.it/php_test.php

          Mobile Test Page: Apache Mobile Test

          Comment


            #6
            Why are you making it hard for yourself, it's so easy..just simple like this..
            PHP Code:
            if(!eregi("text/vnd.wap.wml"$HTTP_ACCEPT))
            {
            header("Location: web/index.php");
            }else{
            header("Location: wap/index.php");

            You listed out all user agents..Lol..
            Last edited by kiLLeR-eyEd_14; 23.08.09, 21:45.
            My Blog: http://jhommark.blogspot.com
            My Facebook: http://www.facebook.com/jhommark
            My Official Site: http://www.undergroundweb.tk
            My Community Site: http://undergroundwap.xtreemhost.com

            Comment


              #7
              Originally posted by anderson View Post
              I just tested anshul's code and it's working nice.
              ..So why no one thanks him ?? ~LoL~ just asking =)
              Did I help you?
              You can help me too
              Your donations will help me finance my studies.

              Comment


                #8
                I don't think is correct, because some mobile browser for example the iPhone don't support wml.

                Comment


                  #9
                  Originally posted by kei_ki7 View Post
                  ..So why no one thanks him ?? ~LoL~ just asking =)
                  why don't you try mine..don't make it hard..it's very simple and easy..you don't need to list down several user agents..Just detect if $http_accept matched with wml and then redirect it to mobile..Although it's mobile, we all know html structure is better than wml..Unless it really doesn't support html..
                  My Blog: http://jhommark.blogspot.com
                  My Facebook: http://www.facebook.com/jhommark
                  My Official Site: http://www.undergroundweb.tk
                  My Community Site: http://undergroundwap.xtreemhost.com

                  Comment


                    #10
                    HTTP_ACCEPT is not a good method to know if a device is a mobile device.
                    A lot of mobile device don'accept wml, so it's not a method to detect device.
                    You need an example ? Try with this devices:
                    Nokia N90
                    Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413

                    Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux armv6l; U) Opera 8.5 [en_US] Maemo browser 0.7.6 RX-34_2007SE_2.2006.51-6

                    HTC Dreams (android)
                    Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) AppleWebKit/525.10 (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2


                    All of this devices dosen't support wml.

                    Comment


                      #11
                      Originally posted by ifuschini View Post
                      HTTP_ACCEPT is not a good method to know if a device is a mobile device.
                      A lot of mobile device don'accept wml, so it's not a method to detect device.
                      You need an example ? Try with this devices:
                      Nokia N90
                      Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413

                      Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux armv6l; U) Opera 8.5 [en_US] Maemo browser 0.7.6 RX-34_2007SE_2.2006.51-6

                      HTC Dreams (android)
                      Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) AppleWebKit/525.10 (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2


                      All of this devices dosen't support wml.
                      so if device doesnt accept WML,
                      it'll be redirected to XHTML site...
                      thats what this is all about..
                      It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt.
                      ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ !
                      ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.
                      キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

                      Comment


                        #12
                        Originally posted by ifuschini View Post
                        HTTP_ACCEPT is not a good method to know if a device is a mobile device.
                        A lot of mobile device don'accept wml, so it's not a method to detect device.
                        You need an example ? Try with this devices:
                        Nokia N90
                        Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413

                        Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux armv6l; U) Opera 8.5 [en_US] Maemo browser 0.7.6 RX-34_2007SE_2.2006.51-6

                        HTC Dreams (android)
                        Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) AppleWebKit/525.10 (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2


                        All of this devices dosen't support wml.
                        You said they doesn't support wml?then they will be redirected to xhtml..what's wrong?lol..Metulj is right..
                        My Blog: http://jhommark.blogspot.com
                        My Facebook: http://www.facebook.com/jhommark
                        My Official Site: http://www.undergroundweb.tk
                        My Community Site: http://undergroundwap.xtreemhost.com

                        Comment


                          #13
                          Originally posted by ifuschini View Post
                          I don't think is correct, because some mobile browser for example the iPhone don't support wml.
                          maybe you're talking that all mobile should be redirected to wml..
                          My Blog: http://jhommark.blogspot.com
                          My Facebook: http://www.facebook.com/jhommark
                          My Official Site: http://www.undergroundweb.tk
                          My Community Site: http://undergroundwap.xtreemhost.com

                          Comment


                            #14
                            I mean that a mobile could be xhtml and wml.
                            Look wurfl.sourceforge.net probably is more clear.

                            Comment


                              #15
                              Look also this: Free Tutorials and Articles. Learn SMS, WML, WMLScript, WAP 2.0, XHTML MP, WCSS/WAP CSS

                              Comment

                              Working...
                              X