<?php
$deviceType =getDeviceType();
if($deviceType=='pc'){
    header('Location: /pc/index.html'); 
    exit;
}
if($deviceType=='mobile'){
    header('Location: /mobile/index.html'); 
    exit;
}
if($deviceType=='tablet'){
    header('Location: /mobile/index.html'); 
    exit;
}

// print_r(getDeviceType());
function getDeviceType()
{
    $userAgent = $_SERVER['HTTP_USER_AGENT'];
    $userAgentLower = strtolower($userAgent);
    
    if (strpos($userAgent, 'iPad') !== false) {
        return 'tablet';
    }
    
    if (strpos($userAgentLower, 'android') !== false) {
        if (strpos($userAgentLower, 'mobile') !== false) {
            return 'mobile';
        } else {
            return 'tablet';
        }
    }
    
    if (strpos($userAgentLower, 'iphone') !== false) {
        if (strpos($userAgentLower, 'wechatdevtools') !== false && strpos($userAgentLower, 'micromessenger') !== false) {
            return 'tablet';
        }
        return 'mobile';
    }
    
    if (strpos($userAgent, 'Macintosh') !== false) {
        if (strpos($userAgent, 'Touch') !== false || strpos($userAgentLower, 'micromessenger') !== false) {
            return 'tablet';
        }
        return 'pc';
    }
    
    if (strpos($userAgentLower, 'tablet') !== false) {
        return 'tablet';
    }
    
    if (strpos($userAgentLower, 'mobile') !== false) {
        return 'mobile';
    }
    
    $mobileKeywords = ['ipod', 'blackberry', 'windows phone'];
    foreach ($mobileKeywords as $keyword) {
        if (strpos($userAgentLower, $keyword) !== false) {
            return 'mobile';
        }
    }
    
    return 'pc';
}

?>