PHP判断手机还是电脑

<?php
$is_mobile = (is_mobile() == true) ? "手机" : "电脑";
echo '<label>php判断结果:</label><span class="red">' . $is_mobile . '</span>';
?>
function is_mobile() {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$mobile_agents = array("240x320", "acer", "acoon", "acs-", "abacho", "ahong", "airness", "alcatel", "amoi",
"android", "anywhereyougo.com", "applewebkit/525", "applewebkit/532", "asus", "audio",
"au-mic", "avantogo", "becker", "benq", "bilbo", "bird", "blackberry", "blazer", "bleu",
"cdm-", "compal", "coolpad", "danger", "dbtel", "dopod", "elaine", "eric", "etouch", "fly ",
"fly_", "fly-", "go.web", "goodaccess", "gradiente", "grundig", "haier", "hedy", "hitachi",
"htc", "huawei", "hutchison", "inno", "ipad", "ipaq", "iphone", "ipod", "jbrowser", "kddi",
"kgt", "kwc", "lenovo", "lg ", "lg2", "lg3", "lg4", "lg5", "lg7", "lg8", "lg9", "lg-", "lge-", "lge9", "longcos", "maemo",
"mercator", "meridian", "micromax", "midp", "mini", "mitsu", "mmm", "mmp", "mobi", "mot-",
"moto", "nec-", "netfront", "newgen", "nexian", "nf-browser", "nintendo", "nitro", "nokia",
"nook", "novarra", "obigo", "palm", "panasonic", "pantech", "philips", "phone", "pg-",
"playstation", "pocket", "pt-", "qc-", "qtek", "rover", "sagem", "sama", "samu", "sanyo",
"samsung", "sch-", "scooter", "sec-", "sendo", "sgh-", "sharp", "siemens", "sie-", "softbank",
"sony", "spice", "sprint", "spv", "symbian", "tablet", "talkabout", "tcl-", "teleca", "telit",
"tianyu", "tim-", "toshiba", "tsm", "up.browser", "utec", "utstar", "verykool", "virgin",
"vk-", "voda", "voxtel", "vx", "wap", "wellco", "wig browser", "wii", "windows ce",
"wireless", "xda", "xde", "zte");
$is_mobile = false;
foreach ($mobile_agents as $device) {
if (stristr($user_agent, $device)) {
$is_mobile = true;
break;
}
}
return $is_mobile;
}

JS判断手机还是电脑

<p><label>js判断结果:</label><span id="rs_js" class="red"></span></p>
if (/AppleWebKit.*Mobile/i.test(navigator.userAgent) || /Android/i.test(navigator.userAgent) || /BlackBerry/i.test(navigator.userAgent) || /IEMobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))) {
if (/iPad/i.test(navigator.userAgent)) {
$("#rs_js").text("iPad平板");
} else {
$("#rs_js").text("手机");
}
} else {
$("#rs_js").text("电脑");
}

PHP和javascript判断用户使用的是手机还是电脑的更多相关文章

  1. JavaScript 判断用户输入的邮箱及手机格式是否正确

    JavaScript判断用户输入的邮箱格式是否正确.判断用户输入的手机号格式是否正确,下面有个不错的示例,感兴趣的朋友可以参考下. 复制代码代码如下: /*  * 功能:判断用户输入的邮箱格式是否正确 ...

  2. JavaScript判断用户是通过电脑端还是移动端访问

    每个浏览器对应的useragent不同,JavaScript通过判断useragent的类型,便可以判断出用户所使用的浏览器类型,包括 IE.Firefox.chrome等.还可以判断用户是否通过移动 ...

  3. JavaScript经典代码【二】【javascript判断用户点了鼠标左键还是右键】

    IE 下 onMouseDown 事件有个 events.button 可以返回一个数值,根据数值判断取得用户按了那个鼠标键 events.button==0 默认.没有按任何按钮. events.b ...

  4. 使用JavaScript判断用户是否为手机设备

    最近在做微信服务号开发,其中遇到一个问题是微信服务号查看的个人的消息,如果点击在浏览器中查看(iOS中是在Safari中打开)应该是跳转到登录页面,因为页面需要从后台获取,因为需要服务端判断,如果是存 ...

  5. Android判断用户是平板还是手机的方法

    public boolean isTabletDevice() {        TelephonyManager telephony = (TelephonyManager) mContext.ge ...

  6. js判断当前的访问是手机还是电脑

    <script type="text/javascript"> //平台.设备和操作系统 var system ={ win : false, mac : false, ...

  7. php判断当前的访问是手机还是电脑

    <?php function check_wap() { if (isset($_SERVER['HTTP_VIA'])) return true; if (isset($_SERVER['HT ...

  8. 【javascript】判断浏览设备是手机还是电脑

    判断页面浏览设备是手机还是电脑,代码如下: function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase( ...

  9. 【javascript】jQuery判断用户右击事件

    jquery 判断用户是鼠标是右击还是左击, // 1 = 鼠标左键 left; 2 = 鼠标中键; 3 = 鼠标右键 $(document).mousedown(function(e) { if(3 ...

随机推荐

  1. 1.跟着微软 https://docs.microsoft.com/zh-cn/dotnet/core/ 学习.net core

    10分钟快速使用 安装之后 打开cmd 第一步. dotnet new console -o firstApp 第二步. cd firstApp 第三部.dotnet run 这样就运行了hello ...

  2. WPF InkCanvas 毛笔效果

    原文:WPF InkCanvas 毛笔效果 1.先来看看InkCanvas的一般用法: <InkCanvas>     <InkCanvas.DefaultDrawingAttrib ...

  3. CMMI能力成熟度模型集成的过程域

    什么是CMMI CMMI全称是Capability Maturity Model Integration, 即能力成熟度模型集成,是由美国国防部(Office of the Secretary of ...

  4. C++第三方日志库Pantheios

    C++第三方日志库Pantheios Kagula 2012-1-11 简介 在项目实践中发现一个好的日志记录非常重要,你需要借助Logging才能跟踪软件中的错误.所以这里研究下第三方C++库Pan ...

  5. NS2网络模拟(4)-吞吐率图

    1: #NS2_有线部分\ForGnuplot.plot 2: 3: #gnuplot> 4: #set xtics 0, 1, 10 5: set grid 6: set xrange [0: ...

  6. 使用Photoshop切图的三种方式

    PhotoShop切图的三种方式 1. 原始切图 (1)选择工具栏中的切片工具 (2)找到要切片的元素,在右侧的图层框中,使元素背景隐藏,然后用切片工具选择需要切片的元素     (3)导出为web常 ...

  7. [自带避雷针]DropShadowEffect导致内存暴涨

    原文:[自带避雷针]DropShadowEffect导致内存暴涨  [自带避雷针]DropShadowEffect导致内存暴涨 周银辉 从学习WPF开始, 就知道"位图效果"不是什 ...

  8. .NET Core 中使用 Humanizer 显示友好时间格式

    今天在将一个 .net framework 项目迁移至 .net core 的过程中,在迁移到显示友好时间格式(比如“1分钟前”,“1小时前”)的代码时,找了找看有没有对应的开源库,结果找到了 Hum ...

  9. jquery map()的用法--遍历数组

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  10. Delphi7文件操作常用函数

    1. AssignFile.Erase AssignFile procedure AssignFile(var F; FileName: string);:给文件变量连接一个外部文件名.这里需要注意的 ...