Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Mobile Device Detection Script

I've posted this before, but it's been updated.

Huge numbers of visits to sites are now via mobile devices and many of our themes are just not up to it.

There are various ways you can configure your site for this.

You can create a wholly separate site in a sub domain http://m.yoursite.com/ or http://mobile.yoursite.com/ which is what a lot of commercial sites now do. With a bit of work using includes/multisite_include.php you could set it up to use the existing db. There are downsides to this not least having to maintain 2 sets of files instead of one when upgrades come along.

Another way is to use a mobile device detection script. When a mobile device is detected the script below defines the theme folder as mobile_themes instead of the standard themes folder.
N.B. You will also have to place a copy of theme/templates in your mobile_themes folder. (see mate tags needed below)

For it to work, you'd need to adapt the theme you're using for your site and place a mobile version of it in the mobile_themes folder. Both themes would need to be the same name.
You would also need to decide of the level of functionality of your mobile site. The more functionality you require, the harder it'll be to configure it for a phone or other small device.

A simple fix would be to only display CENTER thereby disabling the side panels. If you look at the script below you'll see define("MOBILE", "1");. This could be used as a check anywhere you want to change the content for a mobile visitor.

if (MOBILE) { 
   echo "don't show this";
    { echo "show full stuff";

Doing it this way does away with editing core files which as you know is a major pain in the butt when it comes to upgrading.

Meta tags to be added to mobile_themes/templates/header.php

<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width">

In maincore.php
Find line 99

define("THEMES", BASEDIR."themes/");

and delete or comment out and replace with

include INCLUDES."mobile_detect.php";

assuming you've put the script in INCLUDES

This is just a thought experiment and not ready for use as you would have to configure your theme(s) yourself and if you allow users to select their own theme, then this becomes much more difficult.
You would most likely have to lock the theme for users for when their using mobile devices to one theme or just set your mobile site to view only.

Live example: http://gplusphotopages.phpnuclear.com/ (this is still a work in progress and is no where near finished)

| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2012 Nick Jones
| http://www.php-fusion.co.uk/
| Filename: mobile_detect.php
| Author: Chad Smith
| Web: http://detectmobilebrowser.com/
| Adapted for PHP-Fusion by Philip Daly (HobbyMan)
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).

if(preg_match('/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i',substr($useragent,0,4)))
     define("THEMES", BASEDIR."mobile_themes/");
     define("MOBILE", "1");
        } else {
     define("THEMES", BASEDIR."themes/");
     define("MOBILE", "0");

Thread Information
1 post
6703 times
Last Post
Last updated on 7 years ago
You can view all discussion threads in this forum.
You cannot set up a bounty in this discussion thread.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
Users who participated in discussion: HobbyMan