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.
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:");
exit;
}
?>
Now you can check your own.
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example