12 replies
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.
#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;

    }
    ?>
    {{ DiscussionBoard.errors[3495961].message }}
  • Profile picture of the author webpro4hire
    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
    {{ DiscussionBoard.errors[3496487].message }}
    • Originally Posted by FreeBird85 View Post

      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.
      Originally Posted by webpro4hire View Post

      If you'd like a purely client-side javascript solution, I find this ...
      the best script to do the redirection.
      So much for paying attention
      {{ DiscussionBoard.errors[3496590].message }}
  • Profile picture of the author webpro4hire
    Oh Crap!

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

    I retire in shame.

    WebPro
    {{ DiscussionBoard.errors[3496622].message }}
  • Profile picture of the author FreeBird85
    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.
    Signature

    {{ DiscussionBoard.errors[3496892].message }}
  • Profile picture of the author phpbbxpert
    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.
    {{ DiscussionBoard.errors[3497501].message }}
    • Profile picture of the author FreeBird85
      Originally Posted by phpbbxpert View Post

      This code
      <?php
      include("Mobile_Detect.php");
      = new Mobile_Detect();

      if (()) {
      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.

      worked like a charm! Thanks
      Signature

      {{ DiscussionBoard.errors[3497659].message }}
  • Profile picture of the author realdude
    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
    {{ DiscussionBoard.errors[3593011].message }}
    • Profile picture of the author wayfarer
      Originally Posted by realdude View Post

      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
      That's correct.
      Signature
      I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
      {{ DiscussionBoard.errors[3676845].message }}
  • Profile picture of the author jargonbust
    i can some good awesome coders here
    {{ DiscussionBoard.errors[3593686].message }}
    • Profile picture of the author aditiya1920
      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.
      {{ DiscussionBoard.errors[3621461].message }}
  • Profile picture of the author Nail Yener
    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.
    {{ DiscussionBoard.errors[3675615].message }}

Trending Topics