Redirect Mobile Devices with PHP

user_agent.php

<?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/&#8217;); //OR echo “<script>window.location=’http://mobile.site.com'</script>&#8221;; }

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

include(‘user_agent.php’);

?>

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s