Site Admin
Site Admin Founder of MeaningArticles
879 Views

PHP Mobile Device Detection Example

Hello Dev.

Today i will explained How To Mobile Device Detection In PHP Example. This example is so easy to use in php.

The user agent class is simple PHP class which helps to mobile device detection. You should call a method from this class to check if visitors visit your site from mobile devices or tablets or desktop and you can redirect visitor to the suitable website.

You only need to download two files from below. user_agents_config.php file contains all the user agents and user_agent.php file contain UserAgent class. Also note that, those two files should insert at the same directory.

user_agents_config.php

user_agent.php
So let's start to the example.

index.php

<?php
    include_once 'user_agent.php';
    $ua = new UserAgent();
    
    //if site is accessed from mobile, then redirect to the mobile site.
    if($ua->is_mobile()){
        header("Location:https://www.meaningarticles.com");
        exit;
    }
?>

i'm hoping it assist you to, thanks for visit my article if you like my article then proportion together with your friend and social platform.