Ejemplo n.º 1
0
 /**
  * __unset() - unset a variable in this objects namespace.
  *
  * @param string $name - programmatic name of a key, in a <key,value> pair in the current namespace
  * @return true
  */
 protected function __unset($name)
 {
     if ($name === '') {
         throw new Zend_Session_Exception("The '{$name}' key must be a non-empty string");
     }
     return $this->_sessionCore->namespaceUnset($this->_namespace, $name);
 }
Ejemplo n.º 2
0
 /**
  * __unset() - unset a variable in this objects namespace.
  *
  * @param string $name - programmatic name of a key, in a <key,value> pair in the current namespace
  * @return true
  */
 protected function __unset($name)
 {
     if ($name === '') {
         throw Zend::exception('Zend_Session_Exception', __CLASS__ . "::__unset() the '{$name}' key must be a non-empty string");
     }
     return $this->_sessionCore->namespaceUnset($this->_namespace, $name);
 }
Ejemplo n.º 3
0
 public function _ZF_expireAll($args)
 {
     Zend_Session_Core::setOptions(array('remember_me_seconds' => 15, 'gc_probability' => 2));
     session_id($args[0]);
     if (isset($args[1]) && !empty($args[1])) {
         $s = new Zend_Session($args[1]);
     } else {
         $s = new Zend_Session();
     }
     $result = '';
     foreach ($s->getIterator() as $key => $val) {
         $result .= "{$key} === {$val};";
     }
     $core = Zend_Session_Core::getInstance();
     $core->expireSessionCookie();
     $core->writeClose();
     echo $result;
 }
Ejemplo n.º 4
0
 /**
  * _processStartupMetadataNamespace() - this method processes the metadata specific only
  * to a given namespace.  This is typically run at the instantiation of a Zend_Session object.
  *
  * @param string $namespace
  */
 public static function _processStartupMetadataNamespace($namespace)
 {
     if (!isset($_SESSION['__ZF'])) {
         return;
     }
     if (isset($_SESSION['__ZF'][$namespace])) {
         // Expire Namespace by Namespace Hop (ENNH)
         if (isset($_SESSION['__ZF'][$namespace]['ENNH'])) {
             $_SESSION['__ZF'][$namespace]['ENNH']--;
             if ($_SESSION['__ZF'][$namespace]['ENNH'] === 0) {
                 self::$_expiring_data[$namespace] = $_SESSION[$namespace];
                 unset($_SESSION[$namespace]);
                 unset($_SESSION['__ZF'][$namespace]['ENNH']);
             }
         }
         // Expire Namespace Variables by Namespace Hop (ENVNH)
         if (isset($_SESSION['__ZF'][$namespace]['ENVNH'])) {
             foreach ($_SESSION['__ZF'][$namespace]['ENVNH'] as $variable => $hops) {
                 $_SESSION['__ZF'][$namespace]['ENVNH'][$variable]--;
                 if ($_SESSION['__ZF'][$namespace]['ENVNH'][$variable] === 0) {
                     self::$_expiring_data = $_SESSION[$namespace][$variable];
                     unset($_SESSION[$namespace][$variable]);
                     unset($_SESSION['__ZF'][$namespace]['ENVNH'][$variable]);
                 }
             }
         }
     }
     if (empty($_SESSION['__ZF'][$namespace])) {
         unset($_SESSION['__ZF'][$namespace]);
     }
     if (empty($_SESSION['__ZF'])) {
         unset($_SESSION['__ZF']);
     }
 }
Ejemplo n.º 5
0
 /**
  * expireSessionCookie() - Sends an expired session id cookie, causing the client to delete the session cookie
  *
  * @return void
  */
 public static function expireSessionCookie()
 {
     if (self::$_sessionCookieDeleted) {
         return;
     }
     self::$_sessionCookieDeleted = true;
     if (isset($_COOKIE[session_name()])) {
         $cookie_params = session_get_cookie_params();
         setcookie(session_name(), false, 315554400, $cookie_params['path'], $cookie_params['domain'], $cookie_params['secure']);
     }
 }
Ejemplo n.º 6
0
 /**
  * test expiration of namespace variables by hops
  * expect expiration of specified keys in the proper number of hops
  */
 public function testSetExpireSessionVarsByHopsOnUse()
 {
     $s = new Zend_Session('expireGuava');
     $expireBeforeHop = 2;
     $s->setExpirationHops($expireBeforeHop, 'g', true);
     // only count a hop, when namespace is used
     $s->g = 'guava';
     $s->p = 'peach';
     $s->p = 'plum';
     $id = session_id();
     session_write_close();
     // release session so process below can use it
     // we are not accessing (using) the "expireGuava" namespace, so these hops should have no effect
     for ($i = 1; $i <= $expireBeforeHop + 2; $i++) {
         exec($this->script . "expireAll {$id} notused", $result);
         $result = $this->sortResult($result);
         $this->assertTrue($result === '', "iteration over named Zend_Session namespace failed (result='{$result}'; hop #{$i})");
     }
     for ($i = 1; $i <= $expireBeforeHop + 2; $i++) {
         exec($this->script . "expireAll {$id} expireGuava", $result);
         $result = $this->sortResult($result);
         if ($i > $expireBeforeHop) {
             $expect = ';p === plum';
             $this->assertTrue($result === $expect, "unexpected results iterating over named Zend_Session namespace (result='{$result}'; expected '{$expect}'; hop #{$i})");
         } else {
             $expect = ';g === guava;p === plum';
             $this->assertTrue($result === $expect, "unexpected results iterating over named Zend_Session namespace (result='{$result}'; expected '{$expect}'; hop #{$i})");
         }
     }
     session_start();
     // resume artificially suspended session
     $core = Zend_Session_Core::getInstance();
     $core->destroy();
 }
Ejemplo n.º 7
0
 /**
  * Removes an existing authentication token from the location determined by the session
  * namespace and token member name currently set for this object
  *
  * @return void
  */
 public function logout()
 {
     require_once 'Zend/Session/Core.php';
     if (!Zend_Session_Core::isStarted()) {
         Zend_Session_Core::start();
     }
     Zend_Session_Core::setOptions(array('strict' => true));
     require_once 'Zend/Session.php';
     $session = new Zend_Session($this->_sessionNamespace, Zend_Session::SINGLE_INSTANCE);
     if (!isset($session->{$this->_sessionTokenName})) {
         unset($session->{$this->_sessionTokenName});
     }
 }
Ejemplo n.º 8
0
 /**
  * test expiration of namespaces and namespace variables by seconds
  * expect expiration of specified keys/namespace
  */
 public function testSetExpirationSeconds()
 {
     $s = new Zend_Session('expireAll');
     $s->a = 'apple';
     $s->p = 'pear';
     $s->o = 'orange';
     $s->setExpirationSeconds(5);
     $core = Zend_Session_Core::getInstance();
     $core->regenerateId();
     $id = Zend_Session_Core::getId();
     session_write_close();
     // release session so process below can use it
     sleep(4);
     // not long enough for things to expire
     exec($this->script . "expireAll {$id} expireAll", $result);
     $result = $this->sortResult($result);
     $expect = ';a === apple;o === orange;p === pear';
     $this->assertTrue($result === $expect, "iteration over default Zend_Session namespace failed; expecting result === '{$expect}', but got '{$result}'");
     sleep(2);
     // long enough for things to expire (total of 6 seconds waiting, but expires in 5)
     exec($this->script . "expireAll {$id} expireAll", $result);
     $result = array_pop($result);
     $this->assertTrue($result === '', "iteration over default Zend_Session namespace failed; expecting result === '', but got '{$result}')");
     session_start();
     // resume artificially suspended session
     // We could split this into a separate test, but actually, if anything leftover from above
     // contaminates the tests below, that is also a bug that we want to know about.
     $s = new Zend_Session('expireGuava');
     $s->setExpirationSeconds(5, 'g');
     // now try to expire only 1 of the keys in the namespace
     $s->g = 'guava';
     $s->p = 'peach';
     $s->p = 'plum';
     session_write_close();
     // release session so process below can use it
     sleep(6);
     // not long enough for things to expire
     exec($this->script . "expireAll {$id} expireGuava", $result);
     $result = $this->sortResult($result);
     session_start();
     // resume artificially suspended session
     $this->assertTrue($result === ';p === plum', "iteration over named Zend_Session namespace failed (result={$result})");
 }
Ejemplo n.º 9
0
 /**
  * __unset() - unset a variable in this objects namespace.
  *
  * @param string $name
  * @return true
  */
 public function __unset($name)
 {
     return $this->_session_core->namespaceUnset($this->_namespace, $name);
 }