Esempio n. 1
0
 /**
  * Create a token in the user's session
  *
  * @param int    $timeout time in seconds the token should be valid
  * @param string $name    name of session variable
  *
  * @return string token value
  */
 public function createToken($timeout = 300, $name = 'XOOPS_TOKEN')
 {
     $this->garbageCollection($name);
     $timeout = $timeout <= 0 ? 300 : $timeout;
     $token_id = Random::generateOneTimeToken();
     // save token data on the server
     if (!isset($_SESSION[$name . '_SESSION'])) {
         $_SESSION[$name . '_SESSION'] = array();
     }
     $token_data = array('id' => $token_id, 'expire' => time() + (int) $timeout);
     array_push($_SESSION[$name . '_SESSION'], $token_data);
     return $token_id;
 }