Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Mobile site

  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts

    Mobile site

    Ive been asked to make someone a mobile version of there site, its a totally new layout so i want to put it on a subdomain, how would i tell the browser to redirect there? Is there a simple line or two i can put saying if mobile device redirect to xxxx or would it be a javascript redirect?

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Hosting providers have no obligation to help you with this. It's a purely development issue. They probably wont help you with it.

    http://code.google.com/p/php-mobile-detect/ - try that. I haven't used it myself, but if it works, it will be good . Using that, I'm guessing you would just write at the top of the pages you want:
    PHP Code:
    if ($detect->isMobile()) {
        
    // any mobile platform
        
    header("location: http://mobile.yoursite.com/");


  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Ahh thanks, ill take a look at that .

    I did find this
    PHP Code:
    <?php


    /* detect mobile device*/
    $ismobile 0;
    $container $_SERVER['HTTP_USER_AGENT'];

    // A list of mobile devices
    $useragents = array (

    'Blazer' ,
    'Palm' ,
    'Handspring' ,
    'Nokia' ,
    'Kyocera',
    'Samsung' ,
    'Motorola' ,
    'Smartphone',
    'Windows CE' ,
    'Blackberry' ,
    'WAP' ,
    'SonyEricsson',
    'PlayStation Portable',
    'LG',
    'MMP',
    'OPWV',
    'Symbian',
    'EPOC',

    );

    foreach ( 
    $useragents as $useragents ) {
    if(
    strstr($container,$useragents)) {
    $ismobile 1;
    }
    }



    if ( 
    $ismobile == ) {
    echo 
    "<p>mobile device</p>";
    echo 
    $_SERVER['HTTP_USER_AGENT'];
    }

    ?>
    However that foreach loop looks like it couldnt be done a bit better, maybe in_array somehow. If the google code doesnt work (although i cant see anything google post not working) ill try that i found.
    Last edited by tomharto; 09-20-2011 at 12:50 PM.

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    PHP Code:
    if (in_array($_SERVER['HTTP_USER_AGENT'],$useragents)) {
         echo 
    'This is a mobile device ' $_SERVER['HTTP_USER_AGENT'];

    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •