A. PHP如何识别是电脑端或手机移动端访问网站
用css来判断当前页面的宽度和高度,现在pc的分辨率最低都在1200*768以上,iPad pro的宽度为1024px,当宽度大于1100px以上,都可以认为当前访问端为pc,一般iPad的宽度为768px,iPhone X的宽度为375px;所以当宽度低于800以下的,都视为手机移动端,现在的pc和手机自适应页面都是按照这个来区分的。
B. php判断手机电脑并且进行跳转
<?
$wap="手机地址";
$pc="pc地址";
ww($wap,$pc);
function ww($wap,$pc){
if(preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])){header("Location: $wap");
exit;
}else{header("Location: $pc");
exit;}
}
?>
C. 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;
}
D. PHP怎样识别手机与电脑的不同访问
这个可以使用js来判断一下UA就可以了。。
下面是一个手机访问跳转到手机版页面的例子
(functionbrowserRedirect(){
varsUserAgent=navigator.userAgent.toLowerCase();
varbIsIpad=sUserAgent.match(/ipad/i)=='ipad';
varbIsIphone=sUserAgent.match(/iphoneos/i)=='iphoneos';
varbIsMidp=sUserAgent.match(/midp/i)=='midp';
varbIsUc7=sUserAgent.match(/rv:1.2.3.4/i)=='rv:1.2.3.4';
varbIsUc=sUserAgent.match(/ucweb/i)=='web';
varbIsCE=sUserAgent.match(/windowsce/i)=='windowsce';
varbIsWM=sUserAgent.match(/windowsmobile/i)=='windowsmobile';
varbIsAndroid=sUserAgent.match(/android/i)=='android';
if(bIsIpad||bIsIphone||bIsMidp||bIsUc7||bIsUc||bIsCE||bIsWM||bIsAndroid){
window.location.href='/wap/';
}
})();
E. php文件手机上怎么打开
php文件属于脚本语言文件,在正确浏览和使用他需要有相应的解析服务器,现在主流是lamp架构或者lnmp架构的服务器打开并解析php文件
在手机上打开你可以直接用手机里边的文本编辑器打开就可以了,不过这样打开你看到的会是php代码,对于不懂编程的人来说看不懂,没有什么用
F. php程序有电脑版和手机版,怎让手机访问电脑版时自动识别是手机访问跳到手机版去。电脑访问手机版时自
你需要做一个手机页,使用判断语句,因为浏览器有一个自己的标示,如果是手机浏览器就跳到M页,也就是手机页面,这个你需要先在前端CSS做一个手机的匹配页面,然后在将它用PHP实例化;还有你必须在页面底部增加一个可切换,切换为电脑版,手机版的连接;
G. PHP代码,怎么设置根据电脑和手机显示不同内容
构造一个判断函数,匹配列出的agent就行,如果为真就输出数字5或者之类的数据嘛,反之就输出其他的,不会的话再问额解决
H. 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 "电脑访问!";
}
?>
回答不容易,希望能帮到您,满意请帮忙采纳一下,谢谢 !