]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/SessionManager.php
5 * Manages the server-side session
9 protected $session = [];
14 * @param array $session The $_SESSION array (reference)
15 * @param ConfigManager $conf ConfigManager instance (reference)
17 public function __construct(& $session, & $conf)
19 $this->session
= &$session;
24 * Generates a session token
26 * @return string token
28 public function generateToken()
30 $token = sha1(uniqid('', true) .'_'. mt_rand() . $this->conf
->get('credentials.salt'));
31 $this->session
['tokens'][$token] = 1;
36 * Checks the validity of a session token, and destroys it afterwards
38 * @param string $token The token to check
40 * @return bool true if the token is valid, else false
42 public function checkToken($token)
44 if (! isset($this->session
['tokens'][$token])) {
45 // the token is wrong, or has already been used
49 // destroy the token to prevent future use
50 unset($this->session
['tokens'][$token]);