<?phpfunction isMobile(){ // If there is HTTP_X_WAP_PROFILE, it must be a mobile device. if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) { equipment, some service providers will block this information if (isset ($_SERVER['HTTP_VIA'])) { // flase if not found, otherwise true return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false; }// Brainless method, judge the client flag sent by the mobile phone, the compatibility needs to be improved 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' ); // Find mobile browser keywords from HTTP_USER_AGENT if (preg_match("/(" . implode('|', $clientkeywords ) . ")/ i", strtolower($_SERVER['HTTP_USER_AGENT']))) { return true;// Protocol method, because it may be inaccurate, leave it to the final judgment if (isset ($_SERVER['HTTP_ACCEPT'])) { // If it only supports wml and does not support html, it must be a mobile device // If it supports wml and html but wml is a mobile device before 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; { // The terminal is a PC, jump to the PC url echo '<script>location.href=""</script>'; exit; }} else { //pc access address if(isMobile()) { // The terminal is a mobile terminal, jump to the mobile terminal url echo '<script>location.href=""</script>'; exit; }}