maxLife = $now + $maxWebServiceSessionLifeSpan; $this->idleLife = $now + $maxWebServiceSessionIdleTime; HTTP_Session::useCookies(false); //disable cookie usage. may this could be moved out constructor? // only first invocation of following method, which is setExpire //have an effect and any further invocation will be have no effect. HTTP_Session::setExpire($this->maxLife); // this method replaces the new with old time if second params is true //otherwise it subtracts the time from previous time HTTP_Session::setIdle($this->idleLife, true); } function isValid(){ $valid = true; // expired if (HTTP_Session::isExpired()) { $valid = false; HTTP_Session::destroy(); throw new WebServiceException(WebServiceErrorCode::$SESSLIFEOVER,"Session has life span over please login again"); } // idled if (HTTP_Session::isIdle()) { $valid = false; HTTP_Session::destroy(); throw new WebServiceException(WebServiceErrorCode::$SESSIONIDLE,"Session has been invalidated to due lack activity"); } //echo "
is new: ", HTTP_Session::isNew(); //invalid sessionId provided. //echo "
get: ",$this->get($this->sessionVar); if(!$this->get($this->sessionVar) && !HTTP_Session::isNew()){ $valid = false; HTTP_Session::destroy(); throw new WebServiceException(WebServiceErrorCode::$SESSIONIDINVALID,"Session Identifier provided is Invalid"); } return $valid; } function startSession($sid = null,$adoptSession=false){ // if($sid){ // HTTP_Session::id($sid); // } if(!$sid || strlen($sid) ===0){ $sid = null; } //session name is used for guessing the session id by http_session so pass null. HTTP_Session::start(null, $sid); $newSID = HTTP_Session::id(); if(!$sid || $adoptSession==true){ $this->set($this->sessionVar,"true"); }else{ if(!$this->get($this->sessionVar)){ HTTP_Session::destroy(); throw new WebServiceException(WebServiceErrorCode::$SESSIONIDINVALID,"Session Identifier provided is Invalid"); $newSID = null; } } if(!$this->isValid()){ $newSID = null; } $sid = $newSID; return $sid; } function getSessionId(){ return HTTP_Session::id(); } function set($var_name, $var_value){ //TODO test setRef and getRef combination //echo "
setting name: ",$var_name," :value: ",$var_value; HTTP_Session::set($var_name, $var_value); } function get($name){ //echo "
getting for: ",$name," :value: ",HTTP_Session::get($name); return HTTP_Session::get($name); } FUNCTION getError(){ return $this->error; } function destroy(){ HTTP_Session::destroy(); } } ?>