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端页面内容"
%>最后更新于 2023-12-12 14:48:17 并被添加「」标签,已有 2265 位童鞋阅读过。
本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处