Location: PHPKode > scripts > mobiledetect > jamesgpearce-mobiledetect-d395f53/detect.php


This is a simple implementation of a mobile device detection algorithm,
originating from the detection used in the dotMobi WordPress Mobile Pack:


The WordPress Mobile Pack is Licensed under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with the

You may obtain a copy of the License at


Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.


function mobile_detection() {
  if (isset($_SERVER['HTTP_X_WAP_PROFILE']) ||
      isset($_SERVER['HTTP_PROFILE'])) {
    return true;
  $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
  if (in_array(substr($user_agent, 0, 4), mobile_detection_ua_prefixes())) {
    return true;
  $accept = strtolower($_SERVER['HTTP_ACCEPT']);
  if (strpos($accept, 'wap') !== false) {
    return true;
  if (preg_match("/(" . mobile_detection_ua_contains() . ")/i", $user_agent)) {
    return true;
  if (isset($_SERVER['ALL_HTTP']) &&
      strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false) {
    return true;
  return false;

function mobile_detection_ua_prefixes() {
  return array(
    'w3c ',
    'xda ',

function mobile_detection_ua_contains() {
  return implode("|", array(
    'lge vx',
    'nintendo DS',
    'opera mobi',
    'opera mini',
    'windows ce',

Return current item: mobiledetect