# MobileRequestDetector.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2008 by Denis M. Gabaidulin                             *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00017     final class MobileRequestDetector
    00018     {
    00019         static private $headers = array(
    00020             'HTTP_X_WAP_PROFILE',
    00021             'HTTP_PROFILE',
    00022             // has additional info
    00023             'HTTP_X_OS_PREFS',
    00024             // msisdn stuff
    00025             'HTTP_MSISDN',
    00026             'HTTP_X_MSISDN',
    00027             'HTTP_X_NOKIA_MSISDN',
    00028             'HTTP_X_WAP_NETWORK_CLIENT_MSISDN',
    00029             'HTTP_X_UP_CALLING_LINE_ID',
    00030             'HTTP_X_NETWORK_INFO',
    00031             // device caps
    00032             'HTTP_X_UP_DEVCAP_ISCOLOR',
    00033             // ms specific headers
    00034             'HTTP_UA_PIXELS',
    00035             'HTTP_UA_COLOR',
    00036             // TODO: specify value range
    00037             //'HTTP_UA_OS',
    00038             //'HTTP_UA_CPU',
    00039             'HTTP_UA_VOICE',
    00040             // misc
    00041             'HTTP_X_NOKIA_BEARER',
    00042             'HTTP_X_NOKIA_GATEWAY_ID',
    00043             'HTTP_X_NOKIA_WIA_ACCEPT_ORIGINAL',
    00044             'HTTP_X_NOKIA_CONNECTION_MODE',
    00045             'HTTP_X_NOKIA_WTLS',
    00046             'HTTP_X_WAP_PROXY_COOKIE',
    00047             'HTTP_X_WAP_TOD_CODED',
    00048             'HTTP_X_WAP_TOD',
    00049             'HTTP_X_UNIQUEWCID',
    00050             'HTTP_WAP_CONNECTION',
    00051             'HTTP_X_WAP_GATEWAY',
    00052             'HTTP_X_WAP_SESSION_ID',
    00053             'HTTP_X_WAP_NETWORK_CLIENT_IP',
    00054             'HTTP_X_WAP_CLIENT_SDU_SIZE',
    00055             'HTTP_ACCEPT_APPLICATION',
    00056             'HTTP_X_ZTGO_BEARERINFO',
    00057             // lg specific ?
    00058             'HTTP_BEARER_INDICATION'
    00059         );
    00060
    00064         public static function create()
    00065         {
    00066             return new self;
    00067         }
    00068
    00069         public function isOperaMini(array $source)
    00070         {
    00071             // mandatory opera mini header
    00072             return isset($source['HTTP_X_OPERAMINI_FEATURES']);
    00073         }
    00074
    00075         public function isMobile(array $source, $checkAccept = false)
    00076         {
    00077             if ($this->isOperaMini($source))
    00078                 return true;
    00079
    00080             foreach (self::$headers as $header)
    00081                 if (isset($source[$header]))
    00082                     return true;
    00083
    00084             if ($this->isIphone($source))
    00085                 return true;
    00086
    00087             if ($checkAccept)
    00088                 return $this->isMobileByHttpAccept($source);
    00089
    00090             return false;
    00091         }
    00092
    00093         public function isIphone(array $source)
    00094         {
    00095             return (
    00096                 isset($source['HTTP_USER_AGENT'])
    00097                 &&
    00098                     stripos(
    00099                         $source['HTTP_USER_AGENT'],
    00100                         'iphone'
    00101                     ) !== false
    00102             );
    00103         }
    00104
    00105         public function isMobileByHttpAccept(array $source)
    00106         {
    00107             return (
    00108                 isset($source['HTTP_ACCEPT'])
    00109                 &&
    00110                     stripos(
    00111                         $source['HTTP_ACCEPT'],
    00112                         'vnd.wap.wml'
    00113                     ) !== false
    00114             );
    00115         }
    00116     }
    00117 ?>