MobileUtils.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2009 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 
00015     final class MobileUtils extends StaticFactory
00016     {
00017         public static function extractIp(array $headers)
00018         {
00019             if (
00020                 MobileRequestDetector::create()->isOperaMini($headers)
00021                 && isset($headers['HTTP_X_FORWARDED_FOR'])
00022             ) {
00023                 $ips = explode(',', $headers['HTTP_X_FORWARDED_FOR']);
00024 
00025                 if ($ips)
00026                     return trim($ips[count($ips) - 1]);
00027             } elseif (isset($headers['REMOTE_ADDR']))
00028                 return $headers['REMOTE_ADDR'];
00029 
00030             return null;
00031         }
00032         
00033         public static function extractUserAgent(array $headers)
00034         {
00035             if (
00036                 MobileRequestDetector::create()->isOperaMini($headers)
00037                 && isset($headers['HTTP_X_OPERAMINI_PHONE_UA'])
00038             )
00039                 return $headers['HTTP_X_OPERAMINI_PHONE_UA'];
00040             elseif (isset($headers['HTTP_USER_AGENT']))
00041                 return $headers['HTTP_USER_AGENT'];
00042 
00043             return null;
00044         }
00045     }
00046 ?>