php判断各户端是否为手机端

    xiaoxiao2021-12-14  24

    在做网站项目时,经常会遇到有的页面不是响应式的因此做成两个页面来针对用户使用手机和电脑查看该页面的情况;

    这时php在调取模板时就要对此情况进行判断,如果是手机端就显示手机端页面,是PC端就显示PC端页面;

    下面提供一个非常简单的方法来判断:

    function is_mobile() { $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $is_pc = (strpos($agent, 'windows nt')) ? true : false; $is_mac = (strpos($agent, 'mac os')) ? true : false; $is_iphone = (strpos($agent, 'iphone')) ? true : false; $is_android = (strpos($agent, 'android')) ? true : false; $is_ipad = (strpos($agent, 'ipad')) ? true : false; if($is_iphone){ return true; } if($is_android){ return true; } if($is_ipad){ return true; } if($is_pc){ return false; } if($is_mac){ return false; } }

    转载请注明原文地址: https://ju.6miu.com/read-971756.html

    最新回复(0)