Thursday, August 30, 2012

Simple PHP Function to Detect Mobile Users

Simple PHP Function to Detect Mobile Users: iPhone, iPad, Blackberry & Android
<?php
/* 
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/

if( !function_exists('mobile_user_agent_switch') ){
function mobile_user_agent_switch(){
$device = '';

if( stristr($_SERVER['HTTP_USER_AGENT'],'ipad') ) {
$device = "ipad";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'iphone') || strstr($_SERVER['HTTP_USER_AGENT'],'iphone') ) {
$device = "iphone";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'blackberry') ) {
$device = "blackberry";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'android') ) {
$device = "android";
}

if( $device ) {
return $device; 
} return false; {
return false;
}
}
}

?>

No comments:

Post a Comment