When users use mobile terminals such as mobile phones to visit the site, we can detect the user terminal type, if it is a mobile phone users, then guide users to access the mobile screen to adapt to cell phone site. This article describes using PHP and JavaScript code to determine the user terminal type separately.
We use PHP's $_server[' http_user_agent '] to get the user agent of the mobile user's browser, then match the existing mobile browser agent library, if it contains a matching keyword, then judge the mobile (mobile terminal) user.
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", " "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");
$is _mobile = false;
foreach ($mobile _agents as $device) {if (Stristr ($user _agent, $device)) {$is _mobile = true;
Break
} return $is _mobile;
}
The above code functions Is_mobile () to determine the user terminal type, the collection of today's various mobile phone http_user_agent to the array $mobile_agents, and matching. Only Call function Is_mobile () when used. As the following code indicates, when the matching user for the mobile phone access, the page jumps to the website mobile phone version m.jb51.net.
You can also add a JavaScript script directly to the front-end page to determine the user's terminal type. JavaScript is also used to get the user-agent information of the browser and then match the existing user-agent repository.
The above code is not very perfect, interested friends welcome to Add.
Of course, we can also use the response layout to match a variety of different screens, which can save the development costs, but when the customer's functional demand for mobile sites, for the independent mobile site is the best to use in the site to determine the user access terminal type, generally we are in the main home to do judgment, If it is a mobile phone visitors will jump to the mobile version of the page, otherwise the normal PC way to access the page.