forked from bretticus/db-sessions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_handler_encrypted.php
More file actions
44 lines (38 loc) · 1.03 KB
/
session_handler_encrypted.php
File metadata and controls
44 lines (38 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Database Session Hander
*
* @author Brett Millett <bmillett@olwm.com>
* @version 1.0
*/
class SessionHandlerEncrypted extends PDOSessionHandler {
protected $key = NULL;
/**
*
* @param PDO $db
* @param string $key
*/
public function __construct(PDO $db, $key) {
$this->key = substr($key, 0, 24); //make sure no longer than 24 chars.
parent::__construct($db);
}
/**
*
* @param string $session_id
* @return string
*/
public function read($session_id) {
$data = parent::read($session_id);
return mcrypt_decrypt(MCRYPT_3DES, $this->key, base64_decode($data), MCRYPT_MODE_ECB);
}
/**
*
* @param string $session_id
* @param string $session_data
* @return boolean
*/
public function write($session_id, $session_data) {
$session_data = mcrypt_encrypt(MCRYPT_3DES, $this->key, $session_data, MCRYPT_MODE_ECB);
return parent::write($session_id, base64_encode($session_data));
}
}