Thursday, August 30, 2012

Simple PHP Function to Detect Mobile Users

8/30/2012

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

?>

helpful? Share this

The Editorial Team of 4everTutorials consists of a group of PHP Professionals.

0 comments:

 

© 2014 4everTutorials. All rights resevered.

Back To Top