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.


To add an if statement to only make it redirect if it is the home page use this.


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.

Share this:

Email
Facebook
Twitter
Pinterest
Pocket

Premium Themes for WordPress

Looking for an easy-to-use Premium Theme for WordPress? Check out Themes by bavotasan.com and have your site up and running in no time.

Use this WordPress website builder to build powerful websites in no time for your or your clients.

WordPress Hosting

WP Engine – designed from the ground-up to support and enhance the workflow of web designers.

Bluehost – providing quality web hosting solutions since 1996.

About the author

Picture of Luke Perrie

Luke Perrie