in ,

How to Detect Mobile Browser And Redirect Mobile Users To Mobile Website In PHP

Advertisement

We all want to give better user experience to our website visitors. So it is nice to have the mobile friendly version of our websites. This is also recommended as the full version of the website takes enough time to load and users also have problems in navigating the websites on mobile devices. So it is a nice idea to have a mobile-friendly version of the website and redirect mobile visitors to the mobile version of the website.

To do this we use $_SERVER[‘HTTP_USER_AGENT’] PHP variable. It returns the browser information.

Most common mobile OS are

  • Android
  • iPhone
  • BlackBerry
  • iPad

So here is the code to check for these mobile users.

Update

Advertisement

I wrote this code long ago. But, we have better and more effective options now. Now you can us available libraries for easier and effective implementation. Try MobileDetect PHP library.

It is a lightweight PHP class for detecting mobile devices. It combines User-Agent string with HTTP headers to detect the mobile environment. Best thing is that you can individually identify the type of mobile device like smartphone, tablet, Android, iOS and more.

You only need to include the PHP file and create the object of the class to use it.

There are various other functions to make it better and more useful. You can functions like

isTablet() , isiOS() and isAndroidOS(). You can also detect browser by using codes like:

I personally recommend the use of this library for better mobile device detection using PHP.

 

Advertisement

Written by Deepanker

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.

2 Comments

Leave a Reply
  1. Interesting blog! Is your theme custom made or did you download it
    from somewhere? A design like yours with a few simple tweeks would really make
    my blog jump out. Please let me know where you got your design.

    Thank you

  2. Interesting blog! Is your theme custom made or did you download it
    from somewhere? A design like yours with a few simple tweeks would really make
    my blog jump out. Please let me know where you got your design.

    Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading…

How to Install a WordPress Plugin

WYSIHTML5 - Open Source HTML5 Rich Text Editor

WYSIHTML5 – Open Source HTML5 Rich Text Editor