PHP 判断终端是手机还是电脑访问网站代码

用thinkphp做底层框架,判断客户是用pc访问还是手机访问的。

<?php

$platform = platform();//检测访问平台

//print_r($_SERVER);DIE;

define(‘FILE_ROOT‘ , dirname(__FILE__));

define(‘APP_DEBUG‘ , true);

define(‘__BUICK__‘ , true);//

define(‘APP_PUBLIC_PATH‘ , ‘../Public‘);

define(‘THINK_PATH‘, $platform[‘THINK_PATH‘]);

define(‘APP_NAME‘  , $platform[‘APP_NAME‘]);

define(‘APP_PATH‘  , $platform[‘APP_PATH‘]);

require(THINK_PATH.‘/ThinkPHP.php‘);

/**

* 返回平台参数

* 默认返回PC端配置

*/

function platform(){

$form = array( ‘Pc‘     => array(‘THINK_PATH‘ => ‘./App/ThinkPHP/‘,‘APP_NAME‘    => ‘App‘,‘APP_PATH‘    => ‘./App/‘ ) ,

‘Moblie‘ => array(‘THINK_PATH‘ => ‘./Moblie/ThinkPHP/‘,‘APP_NAME‘ => ‘Moblie‘,‘APP_PATH‘ => ‘./Moblie/‘ ) );

$form_key = is_mobile();

return $form[$form_key];

}

//判断是否属手机

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","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 = ‘Pc‘;//默认PC端

foreach ($mobile_agents AS $device) {

if (stristr($user_agent, $device)) {

$is_mobile = ‘Moblie‘;

break;

}

}

//针对移动端没有对应显示样式,需要显示PC端样式的活动

if(strstr($_SERVER[‘REQUEST_URI‘],‘?mobiletopc‘)){

$is_mobile = ‘Pc‘;

}

return $is_mobile;

}

?>

时间: 2024-10-31 07:07:13

PHP 判断终端是手机还是电脑访问网站代码的相关文章

判断是手机还是电脑访问的代码 &nbsp;

判断是手机还是电脑访问的函数代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public function whichpad() {     //检测访问的系统及版本.浏览器版本等信息     $agent = strtolower($_SERVER['HTTP_USER_AGENT']);     $is_iphone = (strpos($agent, 'iphone')) ? true : false;     $is_android = (strpo

浏览器判断终端是手机还是电脑

protected void Page_Load(object sender, EventArgs e) { Response.Write(Request.Headers["User-Agent"].ToString() + "<br/>"); //Response.Write() string agent = Request.Headers["User-Agent"]; if (choose_net(agent)) { Respon

如何判断是手机还是电脑访问网站:

现在由于手机功能的强大,使用手机上网的用户越来越多,那么就需要判断用户是用何种客户端登陆的网站,如果使用的是电脑则使用电脑版本的网页,如果使用的手机则使用手机版本的网页,下面是一段能够判断是手机还是电脑的代码: function check()  {    var userAgentInfo=navigator.userAgent;    var Agents =new Array("Android","iPhone","SymbianOS",&

javascript如何判断是手机还是电脑访问本网页

1 var system ={}; 2 var p = navigator.platform; 3 system.win = p.indexOf("Win") == 0; 4 system.mac = p.indexOf("Mac") == 0; 5 system.x11 = (p == "X11") || (p.indexOf("Linux") == 0); 6 if(system.win||system.mac||syst

同一局域网下手机打开电脑本地网站

同一局域网下手机打开电脑本地网站 一.    打开IIS Win+R --------------打开‘运行’ 输入cmd,按回车----------跳到dos视窗操作界面(小黑窗) 停止IIS(iisreset/stop ) 启动IIS(iisreset/start) 二.    增加网站,及填写和选择你的网站名字,路径,以及端口和IP (http://jingyan.baidu.com/article/72ee561a42bd44e16038df6e.html) 1.首先到控制面板里面安装好

如何判断是手机或电脑访问web

移动设备越来越主流,有很多网站对手机访问并不是特别的友好.所以我们要另外的给手机客户分配针对手机web访问的界面.如何判断是手机还是电脑在访问呢? 首先手机访问时,会附带发送user-agent信息,这个信息里面会有手机号码信息.我们如果可以获取...算了,用脚趾头也会想到,这是属于用户个人隐私信息的,移动和联通公司肯定给屏蔽或加密了.除非你服务器IP是在他们的白名单上. 那么我们换其他方式,当手机通过代理服务器访问的时候,http头信息会毫无疑问的包含一个信息:via.这个信息提供了有价值的判

PHP和JS判断手机还是电脑访问

当用户使用手机等移动终端访问网站时,我们可以通过程序检测用户终端类型,如果是手机用户,则引导用户访问适配手机屏幕的移动站点.本文将介绍分别使用PHP和JAVASCRIPT代码判断用户终端类型. PHP版 我们使用PHP的$_SERVER['HTTP_USER_AGENT']来获取手机用户浏览器的用户代理,然后匹配已有的各种手机浏览器代理库,如果含有匹配的关键字,则判断为手机(移动终端)用户. function is_mobile() { $user_agent = $_SERVER['HTTP_

根据浏览器头判断是手机还是电脑访问

当一个域名对应一个PC端和mobile端的网站时,我们需要根据浏览器的header头做跳转判断,最简单的就是通过js来实现: <script type="text/javascript">     var isOnPc=!(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent));     if(isOnPc){         self.location="/pc/index.

判断客户端是手机访问还是电脑访问网站(php代码)

function check_wap() { if (isset($_SERVER['HTTP_VIA'])) return true; if (isset($_SERVER['HTTP_X_NOKIA_CONNECTION_MODE'])) return true; if (isset($_SERVER['HTTP_X_UP_CALLING_LINE_ID'])) return true; if (strpos(strtoupper($_SERVER['HTTP_ACCEPT']),"VND.