]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/SessionManager.php
5 * Manages the server-side session
9 /** Session expiration timeout, in seconds */
10 public static $INACTIVITY_TIMEOUT = 3600;
12 /** Local reference to the global $_SESSION array */
13 protected $session = [];
18 * @param array $session The $_SESSION array (reference)
19 * @param ConfigManager $conf ConfigManager instance
21 public function __construct(& $session, $conf)
23 $this->session
= &$session;
28 * Generates a session token
30 * @return string token
32 public function generateToken()
34 $token = sha1(uniqid('', true) .'_'. mt_rand() . $this->conf
->get('credentials.salt'));
35 $this->session
['tokens'][$token] = 1;
40 * Checks the validity of a session token, and destroys it afterwards
42 * @param string $token The token to check
44 * @return bool true if the token is valid, else false
46 public function checkToken($token)
48 if (! isset($this->session
['tokens'][$token])) {
49 // the token is wrong, or has already been used
53 // destroy the token to prevent future use
54 unset($this->session
['tokens'][$token]);
59 * Validate session ID to prevent Full Path Disclosure.
62 * The session ID's format depends on the hash algorithm set in PHP settings
64 * @param string $sessionId Session ID
66 * @return true if valid, false otherwise.
68 * @see http://php.net/manual/en/function.hash-algos.php
69 * @see http://php.net/manual/en/session.configuration.php
71 public static function checkId($sessionId)
73 if (empty($sessionId)) {
81 if (!preg_match('/^[a-zA-Z0-9,-]{2,128}$/', $sessionId)) {