導航:首頁 > 電腦視頻 > php判斷是手機訪問還是電腦訪問網站

php判斷是手機訪問還是電腦訪問網站

發布時間:2022-06-23 19:01:17

❶ php如何判斷是手機訪問還是電腦訪問

<?
/** *程 序:iswap.php判斷是否是通過手機訪問
*版 本:Ver 1.0 beta
*修 改:奇跡方舟(imiku.com)
*最後更新:2010.11.4 22:56
*程序返回:@return bool 是否是移動設備
*該程序可以任意傳播和修改,但是請保留以上版權信息!
*/
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'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
return true;
}
}
return false;
}
?>

❷ php中怎樣實現判斷是手機訪問還是電腦瀏覽器訪問

嚴格的講strpos($_SERVER['HTTP_ACCEPT'],'wap')!==false 判斷是不夠的,網上找了段比較全的測試無誤,貼出來mark下:

/**
*判斷是手機訪問pc訪問
*/
protectedfunctioncheck_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=$this->checkSubstrs($mobile_os_list,$browser)||$this->checkSubstrs($mobile_token_list,$browser);
if($found_mobile){
$br="WML";
}else{
$br="WWW";
}
}
if($br=="WML"){
returntrue;
}else{
returnfalse;
}
}

/**
*判斷手機訪問,pc訪問
*/
protectedfunctioncheckSubstrs($list,$str){
$flag=false;
for($i=0;$i<count($list);$i++){
if(strpos($str,$list[$i])>0){
$flag=true;
break;
}
}
return$flag;
}

if($this->check_wap()){
echo'wap';
}else{
echo'pc';
}

❸ 網頁怎麼判斷是電腦瀏覽還是手機終端

不同的網頁判斷基準不一樣

一、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判斷是否通過手機訪問可以通過瀏覽器的UA判斷。。

<?php
if(stripos($_SERVER['HTTP_USER_AGENT'],"android")!=flase||stripos($_SERVER['HTTP_USER_AGENT'],"ios")!=flase||stripos($_SERVER['HTTP_USER_AGENT'],"wp")!=flase)
{
echo '手機訪問';
}
else
{
echo '電腦訪問';
}
?>
主要是因為瀏覽器USER_AGENT有操作系統名稱,所以通過此函數判斷。

❺ 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怎麼判斷客戶是用手機還是用電腦訪問的網站

<?
/** *程 序:iswap.php判斷是否是通過手機訪問
*版 本:Ver 1.0 beta
*修 改:奇跡方舟(imiku.com)
*最後更新:2010.11.4 22:56
*程序返回:@return bool 是否是移動設備
*該程序可以任意傳播和修改,但是請保留以上版權信息!
*/
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'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
return true;
}
}
return false;
}
?>

❼ 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判斷終端是手機還是電腦訪問網站

可以參考下這段代碼,主要是通過HTTP的一些請求判斷終端類型,詳見代碼。

<?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";
}
?>

更多問題可以去php中文網問答社區提問http://www.php.cn/wenda.html,大神在線幫你解決,希望對你有幫助

❾ PHP如何識別是電腦端或手機移動端訪問網站

用css來判斷當前頁面的寬度和高度,現在pc的解析度最低都在1200*768以上,iPad pro的寬度為1024px,當寬度大於1100px以上,都可以認為當前訪問端為pc,一般iPad的寬度為768px,iPhone X的寬度為375px;所以當寬度低於800以下的,都視為手機移動端,現在的pc和手機自適應頁面都是按照這個來區分的。

❿ php怎麼判斷網頁是電腦訪問還是手機訪問

<?php if(strpos($_SERVER['HTTP_ACCEPT'],'wap')!==false) {//手機 }else{ //電腦 }

閱讀全文

與php判斷是手機訪問還是電腦訪問網站相關的資料

熱點內容
軟體更改如何重啟系統恢復 瀏覽:426
書寶網手機版電子書免費下載 瀏覽:370
電腦看電視沒有聲音怎麼辦 瀏覽:490
免費下載測量高程的軟體 瀏覽:512
布米米手機版免費下載 瀏覽:863
哪個軟體可以免費看球場直播 瀏覽:736
拍翡翠用什麼軟體 瀏覽:498
香蜜沉沉燼如霜電視劇免費觀看達達兔 瀏覽:298
蘋果電腦接滑鼠沒反應 瀏覽:481
為什麼電腦用藍牙連的熱點沒有網 瀏覽:901
autocad繪圖軟體免費下載 瀏覽:834
論文用什麼軟體寫 瀏覽:952
電腦怎麼清理內存教程 瀏覽:355
免費微信視頻美顏軟體下載 瀏覽:930
免費下載豆發 瀏覽:218
電腦怎麼增加藍牙模板 瀏覽:883
躲在電腦鍵盤俠 瀏覽:377
2021什麼軟體看電影免費 瀏覽:539
什麼軟體能把視頻鏡面 瀏覽:220
托卡的城市怎麼免費下載 瀏覽:14