Mobile detection script in php

by Guna 2012-06-04 15:43:48

Hi,

Try this code to find the device of the mobile users,


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;
}

if($devc=mobile_user_agent_switch()){
echo $devc;
}
else{
echo "no device";
}

Tagged in:

987
like
0
dislike
0
mail
flag

You must LOGIN to add comments