Mobile Site Redirect

by 12 replies
15
Hey I'm looking for a good working mobile site redirect script. If they visit my homepage on their cell phones I want them to be redirected to the mobile site. Most of the ones I can find are javascript, however there's a lot of mobile phones out there that don't support javascript. So I'm looking for another option, does anybody know of any? thanks.
#programming #mobile #redirect #site
  • code.google(dot)com/p/php-mobile-detect/

    This is a php class that will aloow you to do this easily, and give you more options for specific mobile devices.

    Download that, upload it somewheres.

    Than add this to your index.php page ...

    <?php
    @include("Mobile_Detect.php");
    $detect = new Mobile_Detect();

    if ($detect->isMobile()) {
    header("Location:http://themobilesite.com");
    exit;

    }
    ?>
    • [ 1 ] Thanks
  • If you'd like a purely client-side javascript solution, I find this :

    Mobile « Sebastiano Armeli's Tech Blog

    the best script to do the redirection.

    Cheers,
    WebPro
    • [1] reply
  • Oh Crap!

    speed reading is not all what it's cracked up to be...

    I retire in shame.

    WebPro
  • Alright I'm new to PHP, so please bear with me here. I downloaded that from google code, uploaded it to my directory. I use this domain solely for testing. Anyways, so here's the code of my index.php. Very simple just wanted to test it.

    PHP Code:
    <html>
    <head>
      <meta content="text/html; charset=ISO-8859-1"
     http-equiv="content-type">
      <title>Test</title>
    <?php @include("Mobile_Detect.php");
     = new 
    Mobile_Detect();
    if (()) {
    header("Location:http://google.com");
    exit;
    }
    ?>
    </head>
    <body>
    THIS IS A TEST
    <br>
    </body>
    </html>
    So, when i go to it in the desktop browser, its' fine. I go to the site on my mobile phone I get the following error:

    Warning: Cannot modify header information - headers already sent by (output started at index.php:5) in index.php on line 8.



    I know the answer is probably right right there, but I'm not sure, any help is appreciated, thanks.
  • This code
    <?php
    include("Mobile_Detect.php");
    $detect = new Mobile_Detect();

    if ($detect->isMobile()) {
    header("Location:http://themobilesite.com");
    exit;

    }
    ?>

    Needs to be at the start of the script.
    Eg. before the opening <html> tag

    That error is telling you that there is output sent to the header already at line 5
    <title>Test</title>
    Which is why the redirect needs to be first in the file.
    • [ 1 ] Thanks
    • [1] reply
  • Way cool! Another question, how do you add redirects to different sites? Is this correct:

    if ($detect->isGeneric()) {
    header("Location:http://m.site.com");
    exit;

    }

    if ($detect->isAndroid()) {
    header("Location:http://s.site.com");
    exit;

    }

    Many thanks, Dan
    • [1] reply
  • i can some good awesome coders here
    • [1] reply
    • i just made a simple mobile version, but i cant try if this way really work.

      Please, try access my site through your mobile, hxxp://quickfollower.com

      Please let me know.
  • I found another PHP code for redirection and it works good. Do you have any idea how I can send visitors to the full site from the mobile site? I have a "Full Site" link on the mobile version, but when you click on it, redirect works again and sends you to the mobile site.

    I'm trying to post the code using code tags in BBCode but it seems I can't.

Next Topics on Trending Feed

  • 15

    Hey I'm looking for a good working mobile site redirect script. If they visit my homepage on their cell phones I want them to be redirected to the mobile site. Most of the ones I can find are javascript, however there's a lot of mobile phones out there that don't support javascript. So I'm looking for another option, does anybody know of any? thanks.