Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

How to Detect and Redirect to Mobile Site using PHP

by
Category:php
php html
How to Detect and Redirect to Mobile Site using PHP

We provide a few cases below which describe how to use mobile-detect to alter your site behavior. In this tutorial i will show to simple script how to detect and redirect to mobile site using PHP. You may also like How to Simple HTTP Authentication using PHP and How to create login authentication in codeigniter

There is a PHP class used for detecting mobile devices Mobile Detect we use this class to detect the mobile devices.

HTML and PHP Code

<?php
require_once 'mobile.php';
?>
<html>
    <body>
        <h1>How to Detect and Redirect to Mobile Site using PHP</h1>
    </body>
</html>

PHP Code (mobile.php)

<?php
$detect_device = new Mobile_Detect;

// For All Mobile Devices
if($detect_device->isMobile()) 
{
    header('Location: http://m.dome.com/');
    exit;
}

// For All Tablet Devices
if( $detect_device->isTablet()) 
{
    header('Location: http://m.dome.com/');
    exit;
}

// For Specific Operating System
if( $detect_device->isAndroidOS()) 
{
    echo "<link rel='stylesheet' href='css/android.css' type='text/css' />";  
}
if( $detect_device->isiOS()) 
{
    echo "<link rel='stylesheet' href='css/ios.css' type='text/css' />"; 
}
if( $detect_device->isWindowsPhoneOS()) 
{
    echo "<link rel='stylesheet' href='css/windows.css' type='text/css' />";  
}

0 Comments


Html code work in comment box


Related Post