oxutilsserver.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxUtilsServer
00007 {
00013     private static $_instance = null;
00014 
00020     public static function getInstance()
00021     {
00022         // disable caching for test modules
00023         if ( defined( 'OXID_PHP_UNIT' ) ) {
00024             static $inst = array();
00025             self::$_instance = $inst[oxClassCacheKey()];
00026         }
00027 
00028         if ( !self::$_instance instanceof oxUtilsServer ) {
00029             self::$_instance = oxNew( 'oxUtilsServer');
00030             if ( defined( 'OXID_PHP_UNIT' ) ) {
00031                 $inst[oxClassCacheKey()] = self::$_instance;
00032             }
00033         }
00034         return self::$_instance;
00035     }
00036 
00047     public function setOxCookie( $sName, $sValue = "", $iExpire = 0, $sPath = '/' )
00048     {
00049         //TODO: since setcookie takes more than just 4 params..
00050         // would be nice to have it sending through https only, if in https mode
00051         // or allowing only http access to cookie [no JS access - reduces XSS attack possibility]
00052         // ref: http://lt.php.net/manual/en/function.setcookie.php
00053 
00054         if ( defined('OXID_PHP_UNIT')) {
00055             // do NOT set cookies in php unit.
00056             return;
00057         }
00058         if ( $sPath !== null ) {
00059             return setcookie( $sName, $sValue, $iExpire, $sPath );
00060         } else {
00061             return setcookie( $sName, $sValue, $iExpire );
00062         }
00063     }
00064 
00073     public function getOxCookie( $sName = null )
00074     {
00075         if ( $sName && isset( $_COOKIE[$sName] ) ) {
00076             return oxConfig::checkSpecialChars($_COOKIE[$sName]);
00077         } elseif ( $sName && !isset( $_COOKIE[$sName] ) ) {
00078             return null;
00079         } elseif ( !$sName && isset( $_COOKIE ) ) {
00080             return $_COOKIE;
00081         }
00082         return null;
00083     }
00084 
00090     public function getRemoteAddress()
00091     {
00092         if ( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
00093             $sIP = $_SERVER["HTTP_X_FORWARDED_FOR"];
00094         } elseif ( isset( $_SERVER["HTTP_CLIENT_IP"] ) ) {
00095             $sIP = $_SERVER["HTTP_CLIENT_IP"];
00096         } else {
00097             $sIP = $_SERVER["REMOTE_ADDR"];
00098         }
00099         return $sIP;
00100     }
00101 
00109     public function getServerVar( $sServVar = null )
00110     {
00111         if ( isset( $_SERVER ) ) {
00112             if ( $sServVar && isset( $_SERVER[$sServVar] ) ) {
00113                 return $_SERVER[$sServVar];
00114             } elseif (!$sServVar) {
00115                 return $_SERVER;
00116             }
00117         }
00118         return null;
00119     }
00120 
00121 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5