㈠ php 判断是移动端APP还是移动端浏览器还是PC浏览器
<?phpfunction isMobile(){ // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) { return true; } // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息 if (isset ($_SERVER['HTTP_VIA'])) { // 找不到为flase,否则为true return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false; } // 脑残法,判断手机发送的客户端标志,兼容性有待提高 if (isset ($_SERVER['HTTP_USER_AGENT'])) { $clientkeywords = array ('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile' ); // 从HTTP_USER_AGENT中查找手机浏览器的关键字 if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { return true; } } // 协议法,因为有可能不准确,放到最后判断 if (isset ($_SERVER['HTTP_ACCEPT'])) { // 如果只支持wml并且不支持html那一定是移动设备 // 如果支持wml和html但是wml在html之前则是移动设备 if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) { return true; } } return false;} ?>
㈡ php如何判断用户通过手机wap访问还是电脑直接访问
PHP通过内置全局变量$_SERVER['HTTP_USER_AGENT']来获取用户信息,包括浏览器信息,操作系统等;判断是否是手机还是电脑终端访问,只需判断他的$_SERVER['HTTP_USER_AGENT']信息是否存在手机终端类型即可。示例如下:
<?php
//1.获取用户浏览器信息 等;
$user_agent = $_SERVER['HTTP_USER_AGENT'];
//2.列举常用手机终端类型
$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");
foreach ($mobile_agents as $device) {
if (stristr($user_agent, $device)) {
//手机访问
$is_mobile = true;
break;
}
}
//判断手机标识是否为真
if($is_mobile){
echo "手机访问!";
}else{
echo "电脑访问!";
}
?>
回答不容易,希望能帮到您,满意请帮忙采纳一下,谢谢 !
㈢ 网页怎么判断是电脑浏览还是手机终端
不同的网页判断基准不一样
一、php/html网页判断标准
1、php网页是根据用户访问的设备分辨率来判断是电脑浏览器或者是手机浏览器的。
2、例如php通过如下代码即可实现统计:
<?php
functioncheck_wap(){
if(isset($_SERVER['HTTP_VIA']))returntrue;
if(isset($_SERVER['HTTP_X_NOKIA_CONNECTION_MODE']))returntrue;
if(isset($_SERVER['HTTP_X_UP_CALLING_LINE_ID']))returntrue;
if(strpos(strtoupper($_SERVER['HTTP_ACCEPT']),"VND.WAP.WML")>0){
//Checkwhetherthebrowser/gatewaysaysitacceptsWML.
$br="WML";
}else{
$browser=isset($_SERVER['HTTP_USER_AGENT'])?trim($_SERVER['HTTP_USER_AGENT']):'';
if(empty($browser))returntrue;
$mobile_os_list=array('GoogleWirelessTranscoder','WindowsCE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','OperaMobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');
$mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');
$found_mobile=checkSubstrs($mobile_os_list,$browser)||
checkSubstrs($mobile_token_list,$browser);
if($found_mobile)
$br="WML";
else$br="WWW";
}
if($br=="WML"){
returntrue;
}else{
returnfalse;
}
}
functioncheckSubstrs($list,$str){
$flag=false;
for($i=0;$i<count($list);$i++){
if(strpos($str,$list[$i])>0){
$flag=true;
break;
}
}
return$flag;
}
if(check_wap()){
echo"wap";
}else{
echo"web";
}
?>
二、javajavascript的判断标准:
1、JavaScript不管是判断电脑浏览器还是手机浏览器,都是通过User Agent 来判断;
2、以 javascript判断实力如下:
<coding-1lang="other">
<scripttype="text/javascript">
varbrowser={
versions:function(){
varu=navigator.userAgent,app=navigator.appVersion;
return{
trident:u.indexOf('Trident')>-1,//IE内核
presto:u.indexOf('Presto')>-1,//opera内核
webKit:u.indexOf('AppleWebKit')>-1,//苹果、谷歌内核
gecko:u.indexOf('Gecko')>-1&&u.indexOf('KHTML')==-1,//火狐内核
mobile:!!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/),//是否为移动终端
ios:!!u.match(/(i[^;]+;(U;)?CPU.+MacOSX/),//ios终端
android:u.indexOf('Android')>-1||u.indexOf('Linux')>-1,//android终端或者uc浏览器
iPhone:u.indexOf('iPhone')>-1||u.indexOf('Mac')>-1,//是否为iPhone或者QQHD浏览器
iPad:u.indexOf('iPad')>-1,//是否iPad
webApp:u.indexOf('Safari')==-1//是否web应该程序,没有头部与底部
};
}()
}
document.writeln("是否为移动终端:"+browser.versions.mobile);
document.writeln("ios终端:"+browser.versions.ios);
document.writeln("android终端:"+browser.versions.android);
document.writeln("是否为iPhone:"+browser.versions.iPhone);
document.writeln("是否iPad:"+browser.versions.iPad);
document.writeln(navigator.userAgent);
</script>
</coding>
㈣ PHP判断客户端是电脑还是手机
php判断客户端是手机的代码,版权归原作者,我只是搬运工。
function isMobile()
{
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
{
return true;
}
// 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
if (isset ($_SERVER['HTTP_VIA']))
{
// 找不到为flase,否则为true
return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
}
// 脑残法,判断手机发送的客户端标志,兼容性有待提高
if (isset ($_SERVER['HTTP_USER_AGENT']))
{
$clientkeywords = array ('nokia',
'sony',
'ericsson',
'mot',
'samsung',
'htc',
'sgh',
'lg',
'sharp',
'sie-',
'philips',
'panasonic',
'alcatel',
'lenovo',
'iphone',
'ipod',
'blackberry',
'meizu',
'android',
'netfront',
'symbian',
'ucweb',
'windowsce',
'palm',
'operamini',
'operamobi',
'openwave',
'nexusone',
'cldc',
'midp',
'wap',
'mobile'
);
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
{
return true;
}
}
// 协议法,因为有可能不准确,放到最后判断
if (isset ($_SERVER['HTTP_ACCEPT']))
{
// 如果只支持wml并且不支持html那一定是移动设备
// 如果支持wml和html但是wml在html之前则是移动设备
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'textml') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'textml'))))
{
return true;
}
}
return false;
}
㈤ PHP判断用户在移动端访问还是桌面端访问的代码
<?php
functionisMobile()
{
//如果有HTTP_X_WAP_PROFILE则一定是移动设备
if(isset($_SERVER['HTTP_X_WAP_PROFILE']))
{
returntrue;
}
//如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
if(isset($_SERVER['HTTP_VIA']))
{
//找不到为flase,否则为true
returnstristr($_SERVER['HTTP_VIA'],"wap")?true:false;
}
//脑残法,判断手机发送的客户端标志,兼容性有待提高
if(isset($_SERVER['HTTP_USER_AGENT']))
{
$clientkeywords=array('nokia',
'sony',
'ericsson',
'mot',
'samsung',
'htc',
'sgh',
'lg',
'sharp',
'sie-',
'philips',
'panasonic',
'alcatel',
'lenovo',
'iphone',
'ipod',
'blackberry',
'meizu',
'android',
'netfront',
'symbian',
'ucweb',
'windowsce',
'palm',
'operamini',
'operamobi',
'openwave',
'nexusone',
'cldc',
'midp',
'wap',
'mobile'
);
//从HTTP_USER_AGENT中查找手机浏览器的关键字
if(preg_match("/(".implode('|',$clientkeywords).")/i",strtolower($_SERVER['HTTP_USER_AGENT'])))
{
returntrue;
}
}
//协议法,因为有可能不准确,放到最后判断
if(isset($_SERVER['HTTP_ACCEPT']))
{
//如果只支持wml并且不支持html那一定是移动设备
//如果支持wml和html但是wml在html之前则是移动设备
if((strpos($_SERVER['HTTP_ACCEPT'],'vnd.wap.wml')!==false)&&(strpos($_SERVER['HTTP_ACCEPT'],'text/html')===false||(strpos($_SERVER['HTTP_ACCEPT'],'vnd.wap.wml')<strpos($_SERVER['HTTP_ACCEPT'],'text/html'))))
{
returntrue;
}
}
returnfalse;
}
?>
㈥ php 判断是电脑还是手机浏览器打开
$_SERVER['HTTP_USER_AGENT']。这是用来检查浏览页面的访问者在用什么操作系统(包括版本号)浏览器(包括版本号)和用户个人偏好.其中需要检查用户的agent字符串,它是浏览器发送的HTTP请求的一部分。如:var_mp($_SERVER['HTTP_USER_AGENT']);输出:string(65)"Mozilla/5.0(WindowsNT6.1;rv:12.0)Gecko/20100101Firefox/12.0"例如:该脚本正常执行之后的输出是:正在使用InternetExplorer。/view/3909221.htm
㈦ php如何判断页面是手机端还是pc端
PHP 有个手机检测的库很出名啊 Mobile-Detect
地址:https://packagist.org/packages/mobiledetect/mobiledetectlib
或者
<?php
functionisMobile(){
$useragent=isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:'';
$useragent_commentsblock=preg_match('|(.*?)|',$useragent,$matches)>0?$matches[0]:'';
functionCheckSubstrs($substrs,$text){
foreach($substrsas$substr){
if(false!==strpos($text,$substr)){
returntrue;
}else{
returnfalse;
}
}
}
$mobile_os_list=array('GoogleWirelessTranscoder','WindowsCE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','OperaMobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');
$mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');
$found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock)||CheckSubstrs($mobile_token_list,$useragent);
if($found_mobile){
returntrue;
}else{
returnfalse;
}
}
if(isMobile())
echo'phone';
else
echo'pc';
?>
㈧ php判断客户端是pc还是手机
网上现在有三种观点, 一种是基于浏览器发送的 User-Agent, 但明显这种方法是行不通的, 虽然有人列出了大多数的手机发送的User-Agent, 但依然会有很多手机无法识别, 甚至有些手机浏览器不发送User-Agent, 而且也不能保证以后就不会出新牌子. 下面是一个php的例子, 看过之后你就会知道有多么不可靠. 1. function is_wap(){ 2. $ua = strtolower($_SERVER['HTTP_USER_AGENT']); 3. $uachar = "/(dpwapmobile)/i"; 4. if(($ua == '' preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap')){ 5. return true; 6. }else{ 7. return false; 8. } 9. } 另外一种是判断HTTP_ACCEPT, 这种应该相对可靠一点, 不过HTTP_ACCEPT是非常复杂的, 如果一般的不支持html的浏览器还好说, 你只要判断浏览器支持wml并且不支持html就可以, 但如果浏览器同时支持wml和html那就难办了, 低端手机可能会将wml放到html的前面, 但是很多高端手机或者智能手机对html的支持很好, 所以html也会出现在wml前面. 这是黑莓手机发送的HTTP_ACCEPT application/vnd.rim.html, text/html, application/vnd.wap.xhtml+xml, text/vnd.sun.j2me.app-descriptor, image/vnd.rim.png,image/jpeg, application/x-vnd.rim.pme.b, application/vnd.rim.ucs, image/gif;anim=1, application/vnd.rim.jscriptc;v=0-8-8, application/x-javascript, application/vnd.rim.css;v=1, text/css;media=handheld, application/vnd.wap.wmlc;q=0.9, application/vnd.wap.wmlscriptc;q=0.7, text/vnd.wap.wml;q=0.7, */*;q=0.5 夸张吧? 不过的确是很标准的, 开发人员可以根据这个得到很多信息, 但很多手机都没这么标准的, 如果你查看IE或者FF的HTTP_ACCEPT你会发现它很短. text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8 同样, 给你个php的例子. if (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'],'vnd.wap.wml')!==FALSE) && (strpos($_SERVER['HTTP_ACCEPT'],'text/html')===FALSE (strpos($_SERVER['HTTP_ACCEPT'],'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'],'text/html')) )) {//手机访问 readfile('index.wml'); } else readfile('index.htm'); 原理:如果浏览器支持WML、而且[不支持HTML]或[WML优先于HTML],则判定为手机。但实际上这个原理是不正确的. 还有一种是说判断网关或者IP什么的, 但我个人认为这个很不可靠, 手机的联网方式很多, 比如我开发的时候就是用模拟器的.这个应该不用什么例子了, REMOTE_ADDR 就足够了. 以上是我今天上午的工作成果, 但实际上还是没有找到完美的解决方案, 先写这么多, 有问题请补充或者发送消息给我, 如果你有更好的办法希望可以分享给我, 谢谢.
㈨ php如何判断客户端是pc还是手机
//判断是否是手机
functionis_mobile()
{
$agent=strtolower($_SERVER['HTTP_USER_AGENT']);
$is_pc=(strpos($agent,'windowsnt'))?true:false;
$is_mac=(strpos($agent,'macos'))?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_pc){
returnfalse;
}
if($is_mac){
returntrue;
}
if($is_iphone){
returntrue;
}
if($is_android){
returntrue;
}
if($is_ipad){
returntrue;
}
}
㈩ ThinkPHP中判断是手机端还是电脑端访问的方法
一般是通过访问的时候请求来源的header头文件信息来进行判断的,譬如Android的手机访问的话一般都会在hedear头信息里面带上Android这样的信息,同理Iphone、windows phone都会带。