when website open in mobile redirect to subdomain

$_SERVER – Server and execution environment information

<?php
echo $_SERVER[‘HTTP_USER_AGENT‘];
?>

My Android browser Output:

Mozilla/5.0 (Linux; U; Android 2.1-update1; en-in; HTC_Wildfire_A3333 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari



user_agent.php
Usining strpos() function find position of first occurrence of a string.

<?php

$iphone = strpos($_SERVER[‘HTTP_USER_AGENT’],”iPhone“);
$android = strpos($_SERVER[‘HTTP_USER_AGENT’],”Android“);
$palmpre = strpos($_SERVER[‘HTTP_USER_AGENT’],”webOS“);
$berry = strpos($_SERVER[‘HTTP_USER_AGENT’],”BlackBerry“);
$ipod = strpos($_SERVER[‘HTTP_USER_AGENT’],”iPod“);

if ($iphone || $android || $palmpre || $ipod || $berry == true)
{
header(‘Location: http://mobile.site.com/’);
//OR
echo<script>window.location=’http://mobile.site.com'</script>“;
}

?>


Index.php or Home.php
You have to include like following script.

<?php

include(‘user_agent.php’); // Redirecting http://mobile.site.info
// site.com data

?>
0 CommentsClose Comments

Leave a comment

Newsletter Subscribe

Get the Latest Posts & Articles in Your Email

We Promise Not to Send Spam:)