How To Mobile Device Detection In PHP Example

03-Apr-2023

.

Admin

How To Mobile Device Detection In PHP Example

Hi guys,

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.nicesnippets.com");

exit;

}

?>

Now you can check your own.

I hope it can help you...

#PHP 8

#PHP