use*_*111 2 php mobile device-detection
我需要人们使用PHP检测设备显示分辨率的帮助.
切换界面时我的代码出现问题我有以下代码:
$_page="home";
if(get('page'))
$_page=strtolower(get('page'));
// Check if larger than 800px screen will show this code.
$_pagePath='Includes/desktop/'.$_page.'_left.php';
// Check if the screen is smaller than 800px will display this code.
$_pagePath='Includes/mobile/'.$_page.'_left.php';
if(file_exists($_pagePath))
include $_pagePath;
else
echo 'File '.$_pagePath.' not found';
Run Code Online (Sandbox Code Playgroud)
请帮我完成这段代码.
您将无法使用PHP检测屏幕大小,因为PHP是基于服务器的.但是,您可以使用javascript检测屏幕大小并告诉服务器.最简单的方法是设置cookie.
既然你没有说你想要宽度还是高度,我在下面的代码中假设你只是对那些较大的一个感兴趣.
<script type="text/javascript">
var c=document.cookie;
document.cookie='size='+Math.max(screen.width,screen.height)+';';
</script>
Run Code Online (Sandbox Code Playgroud)
然后在PHP脚本中查看它
if($_COOKIE["size"]>800)
$_pagePath='Includes/mobile/'.$_page.'_left.php';
else
$_pagePath='Includes/desktop/'.$_page.'_left.php';
Run Code Online (Sandbox Code Playgroud)
这种方法的唯一问题是,如果用户第一次连接他还没有cookie,那么服务器将不知道分辨率.同样适用于不接受cookie的用户.
| 归档时间: |
|
| 查看次数: |
12109 次 |
| 最近记录: |