Skip to content

Instantly share code, notes, and snippets.

@ericsk
Created December 30, 2013 15:02

Revisions

  1. ericsk created this gist Dec 30, 2013.
    21 changes: 21 additions & 0 deletions windowsazuresessionhandler.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    /**
    * Callback function for session handler. It's invoked while the session data is being read.
    *
    * @param $sessionId The session ID.
    *
    * @return string The session data. It will retrun empty string if the session doesn't exist.
    */
    public function read($sessionId) {
    try {
    // try to retrieve the session content first to see if it exists
    $result = $this->_tableRestProxy->getEntity($this->_sessionContainer, $this->_sessionContainerPartition, $sessionId);
    // get the entity instance
    $entity = $result->getEntity();
    // deflat the serialized data
    return unserialize(base64_decode($entity->getPropertyValue('data')));
    } catch (ServiceException $e) {
    // the entity doesn't exist, return empty string according to the spec:
    // http://www.php.net/manual/en/sessionhandlerinterface.read.php
    return '';
    }
    }