Author Topic: xác định trình duyệt  (Read 1521 times)

pvandung

  • PHP Intermediate
  • *
  • Posts: 32
    • View Profile
    • Email
xác định trình duyệt
« on: November 15, 2011, 09:18:38 AM »
chào mọi người. tình hình là em đang viết hàm để xác đinh trình duyệt ngươi dùng đang sử dụng. Nhưng lúc so sánh thì ko biết viết tắt của các trình duyệt sao, mình search thì IE viết tắt là "MSIE". ai biết firefox, chorme, opera, sapari viết tắt là gì thì giúp mình với. thanks nhìu

thienha20

  • PHP Intermediate
  • *
  • Posts: 228
    • View Profile
Re: xác định trình duyệt
« Reply #1 on: January 14, 2012, 03:54:13 PM »
trong biến $_SERVER có biến lấy tên trình duyệt đấy trong code cho echo ra, rồi dùng từng trình duyệt mà xem thì biết chứ gì
+Nhận chỉnh sửa, viết addon cscart , opencart từ a->z
+Nhận bảo trì, sửa chữa website với bất kỳ cms hay FW nào miễn không bị mã hóa
Liên hệ : 01266371311

luonghaiviet

  • PHP Starter
  • *
  • Posts: 12
    • View Profile
    • Email
Re: xác định trình duyệt
« Reply #2 on: March 14, 2012, 08:28:34 AM »
Code do mình viết, bạn tham khảo nhé
<?php
global $userBrowser;
global $userAccept;


//Mang xac dinh cac thiet bi di dong
$mobiidentity = array('wapbrowser','up.browser','up/4','mib','cellphone','go.web',
                     'nokia','panasonic','wap','wml-browser','wml','samsung'
                     );

//Mang xac dinh trinh duyet web thong thuong
$pcidentity = array(
          'mozilla','gecko','opera','omniweb','msie','konqueror','safari',
          'netpositive' ,'lynx' ,'elinks' ,'links' ,'w3m' ,'webtv' ,'amaya' ,
          'dillo' ,'ibrowse' ,'icab' ,'crazy browser' ,'internet explorer'
          );

$pspidentity= array('PlayStation Portable');
$iPhoneidentity= array('iphone');


$linkformobile = "http://m.nhadatbinhminh.com";
$linkforweb = "http://nhadatbinhminh.com/tmp/";

// chuyen AGENT ve lower case
$userBrowser = strtolower($_SERVER['HTTP_USER_AGENT']);
// chuyen HTTP_ACCEPT ve lower case
$userAccept= strtolower($_SERVER['HTTP_ACCEPT']);


if (stristr($userAccept,'wml')) {
     $driver = "WML";     
}else{
     //check cho thiet bi di dong thong thuong
     if(check_identity($userBrowser, $mobiidentity))
          $driver = "WML";
     elseif(check_identity($userBrowser, $pcidentity))
          $driver = "PC";
     elseif(check_identity($userBrowser, $pspidentity))
          $driver = "WML";// Co the define lai 1 gia tri khac de sau nay xu ly
     elseif(check_identity($userBrowser, $iPhoneidentity))
          $driver = "WML";// Co the define lai 1 gia tri khac de sau nay xu ly
     else //Khong tim thay thi mac dinh la thiet bi di dong luon ^_^
          $driver = "WML";
}

//Ok ! Sau khi xac dinh thiet bi xong roi thi redirect ve cho thich hop cua no

switch ($driver){
  case 'PC':
    header("Location: ".$linkforweb);
    exit;
  case 'WML':
    header("Location: ".$linkformobile);
  exit;
  }


function check_identity($userBrowser, $identity){
     foreach($identity as $value){
          if(stristr($userBrowser, $value)){
               //Tim thay browser
               return true;
          }
     }
     //Khong tim thay
     return false;
}
?>