PHP Code to Redirect Mobile/Handheld Users
With the amount of people walking around using iPhones or some sort of Blackberry or PDA, it makes sense to provide an alternative landing page for Mobile/Handheld users that is formatted for their device. I was recently hired to create a mobile page by a client and found a great piece of code to help with the whole redirection issue.
The folks over at Detect Mobile Browsers have developed a great tool that checked to see if a user has reached your site through a Mobile/Handheld device, and if so will redirect to the page your choice.
Just download the code off of their site and use their handy Function Generator to configure it how you want.
To configured it to treat everything as a Mobile/Handheld device use this code.
<?php
include('mobile_device_detect.php');
mobile_device_detect(true,true,true,true,'http://your-site.com/your-site-mobile-page',false);
?>
To add an if statement to only make it redirect if it is the home page use this.
<?php
if(is_home()) {
include('mobile_device_detect.php');
mobile_device_detect(true,true,true,true,'http://your-site.com/your-site-mobile-page',false);
}
?>
Add this to the top of your header.php file and uploaded their mobile_device_detect.php file to your main directory. If you are not using WordPress, just add the first bit of code above (without the if statement) to the top of your index.php file.
NOTE: This will only work if your site is built with PHP.






Hi,
try to use Apache Mobile Filter, is very useful to manage mobile device access, it’s based on WURFL as device repository.
For more info: http://www.idelfuschini.it/apache-mobile-filter.html
I have published the new version of Apache Mobile Filter, now the filter is give to you the information of capabilities as apache environment.
Now you can develope in any language (php,jsp, ruby etc.) and have the information of mobile capability.
Read more info here: http://www.idelfuschini.it/it/apache-mobile-filter-v2x.html
Is this working for all mobile devices?
Hi,
To help people to do mobile device detection we have published two free ways to do device detection: detectFree and Movila Detection proxy.
DetectFree works as a service. You need to add a small JavaScript script in to your website and it checks whether the browser is mobile or not.
Movila Detection proxy is a full HTTP proxy which has mobile device detection as a one feature.
Link: Mobile device detection
Hope this helps.
The “Apache Mobile Filter” is one of the modules of “Apache Module Registry” portal (http://modules.apache.org/search.php?id=1787)
Thanks for these modules, i was searching for this only.
Uhh! This is a dream come true. It solves SOOOO many problems.