Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

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) {
		return true;

// how to use 
detectAndroiod('android', 'https://arjunphp.com/');

Leave a Reply