Detect mobile browser using PHP


Hello Friends!

Hope you all are doing well! 🙂

If you want to check that your website is browsing in mobile phone and desktop OR want to add the any condition for mobile/desktop then use code given below :

<?php 
function is_mobile_browser() {
 $is_mobile = (bool) preg_match( '#\b(ip(hone|od)|android\b.+\bmobile|opera m(ob|in)i|windows (phone|ce)|blackberry' . '|s(ymbian|eries60|amsung)|p(alm|rofile/midp|laystation portable)|nokia|fennec|htc[\-_]' . '|up\.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\b#i', $_SERVER['HTTP_USER_AGENT'] );

 return $is_mobile;
}

if(is_mobile_browser())
{
 echo "Site is running on Mobile";
 }else
 {
 echo "Site is running on Desktop";
 }
?>

Enjoy Code!

Advertisements

Sr. Software Engineer

Tagged with: , , ,
Posted in Drupal, Joomla, PHP, Wordpress

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: