Posted in PHP Tutorial

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

How to Detect Mobile Browser And Redirect Mobile Users To Mobile Website In PHP Posted on May 22, 20121 Comment

Deepanker Verma is the CEO of Techlomedia and a full time blogger. On this blog, he shares web design resources, SEO tips blog monetization tips.

Best WordPress Hosting

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

Advertisement

  • Android
  • iPhone
  • BlackBerry
  • iPad

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

Update

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

Deepanker Verma is the CEO of Techlomedia and a full time blogger. On this blog, he shares web design resources, SEO tips blog monetization tips.

1 thought on “How to Detect Mobile Browser And Redirect Mobile Users To Mobile Website In PHP

  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

Leave a Reply

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

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Receive fresh web design resources and SEO tips in your email by our weekly newsletter

You have Successfully Subscribed!