PHP to determine whether the terminal is a mobile phone or computer access to the site code

Source: Internet
Author: User

Use thinkphp to do the bottom frame, to determine whether the customer is accessed with a PC or a mobile phone.

<?php

$platform = Platform ();//detection Access Platform

Print_r ($_server);D ie;

Define (' File_root ', DirName (__file__));

Define (' App_debug ', true);

Define (' __buick__ ', true);//

Define (' App_public_path ', ' ... /public ');

Define (' Think_path ', $platform [' Think_path ']);

Define (' App_name ', $platform [' app_name ']);

Define (' App_path ', $platform [' App_path ']);

Require (Think_path. ' /thinkphp.php ');

/**

* Return to platform parameters

* Return to PC-side configuration by default

*/

function platform () {

$form = Array (' Pc ' = = Array (' think_path ' + = './app/thinkphp/', ' app_name ' = ' App ', ' App_path ') './app/'),

' moblie ' = = Array (' think_path ' = ' = './moblie/thinkphp/', ' app_name ' = ' moblie ', ' app_path ' and ' = ')./moblie/ '));

$form _key = Is_mobile ();

return $form [$form _key];

}

Determine if it is a mobile phone

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",

"Huawei", "Hutchison", "Inno", "ipad", "iPAQ", "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 = ' PC ';//default PC-side

foreach ($mobile _agents as $device) {

if (Stristr ($user _agent, $device)) {

$is _mobile = ' Moblie ';

Break

}

}

There is no corresponding display style for the mobile side, need to display the PC-side style of activity

if (strstr ($_server[' Request_uri '), '? Mobiletopc ')) {

$is _mobile = ' Pc ';

}

return $is _mobile;

}

?>

PHP to determine whether the terminal is a mobile phone or computer access to the site code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.