Skip to content

Android Detection with PHP

Last updated on July 7, 2017

Device detection place very important role in applying new strategies for improving business and user experience. So Here is the small PHP function it will redirect user to new location if user device is Andriod.Using PHP’s $_SERVER variable we can analyze requested user agent.

  function detectDevice($agent , $redirect = false) 
  {
	$user_agent = $_SERVER['HTTP_USER_AGENT'];
	if(stripos($user_agent,$agent) !== false)
	{ 
		if($redirect) {
		header('Location:'.$redirect);
		exit();
		}
		return true;
	}
 }


// how to use 
detectAndroiod('android', 'https://arjunphp.com/');
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments