$_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.phpUsining 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/');
//ORecho "
<script>window.location='http://mobile.site.com'</script>";
}
?>
Index.php or Home.phpYou have to include like following script.
<?php
include(
'user_agent.php');
// Redirecting http://mobile.site.info// site.com data
?>