Detect Mobile Device - Php

How to detect mobile device using php code?

Snippet Code


  
Rate this page :
  [ 0 votes]

This php code can be used to find mobile device.Here "checkMobile()" function is used to detect mobile device.

<?php function checkMobile() { if (preg_match("/Mobile|Android|BlackBerry|iPhone|Windows Phone/", $_SERVER['HTTP_USER_AGENT'])) { return true; // header(Location: MOBILE SITE); } } if(checkMobile()) { echo "Mobile device detected"; } else { echo "Desktop detected"; } ?>

Tags


Ask Questions

Ask Question