00001 <?php
00002
00006 class oxUtilsServer extends oxSuperCfg
00007 {
00013 private static $_instance = null;
00014
00020 protected $_aUserCookie = array();
00021
00027 public static function getInstance()
00028 {
00029
00030 if ( defined( 'OXID_PHP_UNIT' ) ) {
00031 static $inst = array();
00032 self::$_instance = $inst[oxClassCacheKey()];
00033 }
00034
00035 if ( !self::$_instance instanceof oxUtilsServer ) {
00036 self::$_instance = oxNew( 'oxUtilsServer');
00037 if ( defined( 'OXID_PHP_UNIT' ) ) {
00038 $inst[oxClassCacheKey()] = self::$_instance;
00039 }
00040 }
00041 return self::$_instance;
00042 }
00043
00054 public function setOxCookie( $sName, $sValue = "", $iExpire = 0, $sPath = '/' )
00055 {
00056
00057
00058
00059
00060
00061 if ( defined('OXID_PHP_UNIT')) {
00062
00063 return;
00064 }
00065 if ( $sPath !== null ) {
00066 return setcookie( $sName, $sValue, $iExpire, $sPath );
00067 } else {
00068 return setcookie( $sName, $sValue, $iExpire );
00069 }
00070 }
00071
00080 public function getOxCookie( $sName = null )
00081 {
00082 $sValue = null;
00083 if ( $sName && isset( $_COOKIE[$sName] ) ) {
00084 $sValue = oxConfig::checkSpecialChars($_COOKIE[$sName]);
00085 } elseif ( $sName && !isset( $_COOKIE[$sName] ) ) {
00086 $sValue = null;
00087 } elseif ( !$sName && isset( $_COOKIE ) ) {
00088 $sValue = $_COOKIE;
00089 }
00090 return $sValue;
00091 }
00092
00098 public function getRemoteAddress()
00099 {
00100 if ( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
00101 $sIP = $_SERVER["HTTP_X_FORWARDED_FOR"];
00102 } elseif ( isset( $_SERVER["HTTP_CLIENT_IP"] ) ) {
00103 $sIP = $_SERVER["HTTP_CLIENT_IP"];
00104 } else {
00105 $sIP = $_SERVER["REMOTE_ADDR"];
00106 }
00107 return $sIP;
00108 }
00109
00117 public function getServerVar( $sServVar = null )
00118 {
00119 $sValue = null;
00120 if ( isset( $_SERVER ) ) {
00121 if ( $sServVar && isset( $_SERVER[$sServVar] ) ) {
00122 $sValue = $_SERVER[$sServVar];
00123 } elseif ( !$sServVar ) {
00124 $sValue = $_SERVER;
00125 }
00126 }
00127 return $sValue;
00128 }
00129
00140 public function setUserCookie( $sUser, $sPassword, $sShopId = null, $iTimeout = 31536000 )
00141 {
00142 $sShopId = ( !$sShopId ) ? $this->getConfig()->getShopId() : $sShopId;
00143 $this->_aUserCookie[$sShopId] = $sUser . '@@@' . crypt( $sPassword, 'ox' );
00144 $this->setOxCookie( 'oxid_' . $sShopId, $this->_aUserCookie[$sShopId], oxUtilsDate::getInstance()->getTime() + $iTimeout, '/' );
00145 }
00146
00154 public function deleteUserCookie( $sShopId = null )
00155 {
00156 $sShopId = ( !$sShopId ) ? $this->getConfig()->getShopId() : $sShopId;
00157 $this->_aUserCookie[$sShopId] = '';
00158 $this->setOxCookie( 'oxid_'.$sShopId, '', oxUtilsDate::getInstance()->getTime() - 3600, '/' );
00159 }
00160
00168 public function getUserCookie( $sShopId = null )
00169 {
00170 $sShopId = ( !$sShopId ) ? parent::getConfig()->getShopID() : $sShopId;
00171 if ( $this->_aUserCookie[$sShopId] !== null ) {
00172 if ( !$this->_aUserCookie[$sShopId] ) {
00173
00174 return null;
00175 }
00176 return $this->_aUserCookie[$sShopId];
00177 }
00178
00179 return $this->_aUserCookie[$sShopId] = $this->getOxCookie( 'oxid_'.$sShopId );
00180 }
00181 }