Mobile Browser Detection and Redirection using PHP

      Comments Off on Mobile Browser Detection and Redirection using PHP

This is a very simple script to detect the mobile browser and redirect the customers to the mobile version of the website. It is very easy to use and is of just few lines of code.

$_SERVER – an array containing information such as headers, paths, and script locations. (Know more)

user_agent.php
Create a file with the following script and name it as user_agent.php

<?php
$isMobile = (bool)preg_match(‘#\b(ip(hone|od|ad)|android|opera m(ob|in)i|windows (phone|ce)|blackberry|tablet’ . ‘|s(ymbian|eries60|amsung)|p(laybook|alm|rofile/midp|laystation portable)|nokia|fennec|htc[\-_]’ . ‘|mobile|up\.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\b#i’, $_SERVER[‘HTTP_USER_AGENT’] );
if ($isMobile)
{
header(‘Location: http://m.example.com /’);
//OR
echo “<script>window.location=’http://m.example.com'</script>”;
}
?>

in index.php or home.php
You have to include the above script like this.

<?php
include(‘user_agent.php’);  // Redirecting http://m.example.com
// code for example.com page
?>

Author: Teji

i am admin


Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home4/webdekqj/public_html/blog/wp-content/themes/webdesignerinc/single.php on line 32

Warning: include(http://webdesignerinc.com/googleadd.php): Failed to open stream: no suitable wrapper could be found in /home4/webdekqj/public_html/blog/wp-content/themes/webdesignerinc/single.php on line 32

Warning: include(): Failed opening 'http://webdesignerinc.com/googleadd.php' for inclusion (include_path='.:/opt/cpanel/ea-php80/root/usr/share/pear') in /home4/webdekqj/public_html/blog/wp-content/themes/webdesignerinc/single.php on line 32