Mobile Redirect

This thread is an attempt to at least partially reclaim some of the information from our now lost conversation. This topic concerns Google’s change to their website rankings based on mobile friendliness of said sites. The most significant contribution in my opinion was made by Wim, but others also shared their preferred techniques to preserve full site access while meeting Google’s standards. The salient points of this thread could be very helpful to anyone who is trying to comply with ‘Mobile Friendly’ criteria. Also bear in mind that Mobile Redirection isn’t Google’s preferred method of meeting their mobile standards.

Wim posted the, for me anyway, the critical technique for such redirection because it preserved access to the full web site from a mobile phone, didn’t insist that tablets be at first shunted off onto the mobile track, and met Google’s criteria regarding mobile friendliness.

There is a script, called ‘Mobile_Detect.php’ that performs all of the grunt work in checking for mobile platforms when users access a web site. It is available here and more information is on Github.

Using it with the Saratoga template via Wim’s technique is fairly straightforward. The ‘Mobile_Detect.php’ script should be downloaded and placed in the root of your site. Then the following code should be added to ‘top.php’ (context included):

//Version  V3.04 - 05-Feb-2013 - added support for HTML5+UTF8
############################################################################
$cookie         = 'mobile_skip';          // or use your own name
#
$redirect_mobi  = 'http://your.mobile.sites/mobilepage';  // set to your mobile site/page
#
$mobile 	= false;                        // default we do not go to the mobile site
if (!isset ($_COOKIE[$cookie])) {
  require_once 'Mobile_Detect.php';       // credits : http://mobiledetect.net/  
  $detect = new Mobile_Detect;
  if( $detect->isMobile() && !$detect->isTablet() ){
    $mobile = true; 
    if (isset ($_REQUEST['pcSite']) || isset ($_SESSION['pcSite']) ) {
      $mobile         = false;
    }  // eo if pcSite
  }  // eo detect mobile
  if ($mobile == true) {
    header ("Location: $redirect_mobi");	// go to the mobile site			
      exit;
  } // eo is mobile    
}  // eo cookie set
setcookie($cookie, "skip", time()+3600);        // cookie expires in 1 hour

Then you need to add the ‘?pcSite=Y’ to the link to your main site in ‘cell-footer.php’ for the ‘cell.php’ mobile scripts

	<a href="http://your.web.site/index.php?pcSite=Y">View the full version</a>.</div>

and/or to ‘AltAjaxDesktopConfig6.php’

$mainsite = "index.php?pcSite=Y"; // Path and name of main site for mobile site's button to display full dashboard

if you use Scott Thompson’s ‘WWL-mobile.php’.

Briefly, anytime your web site is loaded unless the $cookie is set ‘Mobile-Detect.php’ checks for a mobile viewer. The code then redirects to the site’s mobile page(s) when a mobile viewer NOT a tablet is detected while also setting the $cookie. If the mobile viewer requests the main site however, it’s available because redirection won’t occur until the $cookie expires.

=D>

I used the code from gwwilk and it worked

The purpose of this code is to redirect mobile devices to the mobile site to satisfy the google mobile friendly test

I already had a mobile site at
http://www.642weather.com/weather/mobile/
I made it in 2007 with the free code from Jim McMurry
//wap page using Weather Display provided data version 1.2

But my site still failed the google mobile friendly test because the main site did not redirect to it

First i uploaded he file Mobile_Detect.php to the root directory of my site,
then I added the code to my index.php, but on some some templates you can use use top.php

Next, I edited the index.php in my mobile page folder:
mine is at /mobile/index.php

I added this link near the bottom of the page HTML: (change the url to your actual site)

<a href="http://www.yoursite.com/index.php?pcSite=Y">View Full Site</a>

I did have to make a few modifications to my site to pass the mobile friendly test:
I only had to modify the three php pages in my mobile directory.
I had to add an extra line break between the navigation links to increase the tap targets spacing



I had to add a meta code to the head section of the HTML to set a view port to 300 pixels wide

<meta name="viewport" content="width=300, initial-scale=1">

I also had to change the doc type to HTML5

<!DOCTYPE html>

Now my weather site passes the mobile friendly test

Thanks Mike. It seems by putting that script in the index page rather than the top file did the trick for me.

(From www.xkcd.com)

lol :lol:

Priceless! :lol:

Hi Jerry,
i’ve just installed this script but i’ve the same problem about header already sent issue :frowning:

http://www.meteocarmignano.it/index.php

Just were did you put the extra statements, in which script?

It should go into top.php as that is the place were the headers are outputted. The error message mentions top_contact.php but I assume that is more or less the same as the normal top.php.

In the postings which were lost in the disk failure there was a zip, I attach it again.
You only have to add 1 line to top.php (and your top_contact.php) IMMIDIATLY after the first <?php at line 1

<?php 
include 'check_mobile.php';
############################################################################
# A Project of TNET Services, Inc. and Saratoga-Weather.org (Base-* template sets)
############################################################################
#
#	Project:	Sample Included Website Design
#	Module:		top.php

This works OK with me and a few other sites.

Wim


check_mobile.php.zip (1.01 KB)

Wow, works!
Many many thanks Wim :slight_smile:

One thing:

Is it possible to show a message about redirect?
In this way visitors can choose if use redirect or not.
What doyou think about?

No, then google will not accept that as mobile friendly.

But the whole idea is that you have a button on the mobile site to go to the main site.
http://www.weerstation-wilsele.be/index.php?p=110 button is labeled PC site.

Arriving at the PC -site, that link is detected by this code: if (isset ($_REQUEST[‘pcSite’]) and a cookie is set to keep you at the main site.

So redirect is automatic but any user who wants to go to the main site will go there using the button and stay there for as long as he/she wants
until the last visit is more then 1 hour ago. Then the cookie is expired and the visitor goes to the mobile site again.

Wim

Ok,
thanks for your support!
Regards,

Alessandro

Its official… Lol

[quote]
North Bend , Washington Weather
www.northbendweather.com

Noooooooooooooooooooo
I’ve just created button hahahahaha
But it didn’t work.
If i push button i come back to mobile site, not desktop site.
http://www.meteocarmignano.it/WWL-mobile.php

What’s wrong? :oops:
Probably i wronged position to this code:

 if (isset ($_REQUEST['pcSite']) 

Your button isn’t set right… You need to use this…

View Full Site

Please read the first post, you have to add an indication ($_REQUEST[‘pcSite’]) that the user pushed that button by adding after index.php?pcSite=y
Otherwise the top.php can not know that there is a button pressed.
As support people, also programs are not clairvoyant.

Wim

The name of that extra text MUST match the $_REQUEST[‘???’]
So both should use the same name!.
All those example scripts are slightly different, so check both the code in the top.php
Wim

Sorry Wim,
i’ve installed new version with new button at the bottom.
http://www.meteocarmignano.it/WWL-mobile.php
Insert this code:

$mainsite = "index.php?pcSite=Y"; // Path and name of main site for mobile site's button to display full dashboard

and the header section of index.php page:

<?php($_REQUEST['pcSite']) ?>

but redirect shows white page :oops:

But please READ the first post.
DO NOT enter code at random. I am not at home so remove

<?php($_REQUEST['pcSite']) ?>

and leave until you understand the first post…

Step 1: Add detection code to top.php.
That code checks incoming request if $_REQUEST[‘some name that signals I am coming from a mobile device’] is present.
The first post and my include use $_REQUEST[‘pcSite’] but others use other names for that.

You can copy paste the code from the first post or use an include as in my example.

Step 2: Add a button which has index.php?same name as used in detection script
So index.php?pcsite=y for the button, when you are usinmg the example in the first post of my include.

Wim

Wim,
you’re right but if i put that code into top.php i’ve the error about headers already sent :frowning:

I’ve just insert that code and look at here: http://www.meteocarmignano.it

Edit:
I had already put your code but i didn’t remember to change the same cookie name #-o #-o #-o
Now it works

Wim,
it takes patience with me :smiley: :smiley: :smiley:

Thanks to all for kind support.
Regards,

Alessandro