PC端访问直接显示当前页面,移动端、手机端访问跳转到移动网站的代码

PC端访问直接显示当前页面,移动端、手机端访问跳转到移动网站的代码
PHP:

<?php
$mobileDevices = array("Android", "iPhone", "iPad", "Windows Phone");

$agent = $_SERVER['HTTP_USER_AGENT'];
$isMobile = false;
foreach ($mobileDevices as $device) {
    if (strpos($agent, $device) !== false) {
        $isMobile = true;
        break;
    }
}

if ($isMobile) {
    header("Location: http://yaoge.me/wap");
    exit;
}

// PC端访问时的页面内容
echo "PC端页面内容";
?>

ASP:

<%
Function IsMobileDevice()
    Dim mobileDevices, agent, i
    IsMobileDevice = False
    mobileDevices = Array("Android", "iPhone", "iPad", "Windows Phone")
    agent = Request.ServerVariables("HTTP_USER_AGENT")
    
    For i = LBound(mobileDevices) To UBound(mobileDevices)
        If InStr(1, agent, mobileDevices(i), vbTextCompare) > 0 Then
            IsMobileDevice = True
            Exit Function
        End If
    Next
End Function

If IsMobileDevice() Then
    Response.Redirect "http://yaoge.me/wap"
    Response.End
End If

' PC端访问时的页面内容
Response.Write "PC端页面内容"
%>

发表新评论