|
Revision 1273, 2.1 kB
(checked in by jjb, 2 years ago)
|
#885, #729
- Sessions last for 10 years, and sessions are not "garbage collected" for 10 years.
- The user may specify a custom path for session data to be stored
- The user may turn on the experimental DB session storage system
There is a jumble of mediocre documentation about the various dimensions in php sessions-- the consensus seems to be that session data might be "garbage collected" before the session data expires. I cannot imagine what "garbage collection" could possibly mean in this case-- in call other cases in computer science it means data that the program is absolutely certain is not being used by some part of the system. Here it seems to be a simplistic notion of time-based expiration.
Theses were helpful:
http://www.captain.at/howto-php-sessions.php
http://www.php.net/manual/en/ref.session.php#68537
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
if (defined('DBSESSIONS')) |
|---|
| 4 |
session_set_save_handler( '_open', |
|---|
| 5 |
'_close', |
|---|
| 6 |
'_read', |
|---|
| 7 |
'_write', |
|---|
| 8 |
'_destroy', |
|---|
| 9 |
'_clean' ); |
|---|
| 10 |
|
|---|
| 11 |
function _open() |
|---|
| 12 |
{ |
|---|
| 13 |
global $_sess_db, $wpdb; |
|---|
| 14 |
|
|---|
| 15 |
if ($_sess_db = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)) |
|---|
| 16 |
|
|---|
| 17 |
mysql_select_db(DB_NAME, $_sess_db); |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
return FALSE; |
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
_close() |
|---|
| 24 |
|
|---|
| 25 |
$_sess_db, $wpdb; |
|---|
| 26 |
|
|---|
| 27 |
return mysql_close($_sess_db); |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
_read($id) |
|---|
| 31 |
|
|---|
| 32 |
$_sess_db, $wpdb; |
|---|
| 33 |
|
|---|
| 34 |
$id = mysql_real_escape_string($id); |
|---|
| 35 |
|
|---|
| 36 |
$sql = "SELECT data |
|---|
| 37 |
|
|---|
| 38 |
; |
|---|
| 39 |
|
|---|
| 40 |
$result = mysql_query($sql, $_sess_db)) |
|---|
| 41 |
|
|---|
| 42 |
mysql_num_rows($result)) |
|---|
| 43 |
|
|---|
| 44 |
$record = mysql_fetch_assoc($result); |
|---|
| 45 |
|
|---|
| 46 |
$record['data']; |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
''; |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
_write($id, $data) |
|---|
| 54 |
|
|---|
| 55 |
$_sess_db, $wpdb; |
|---|
| 56 |
$access = time(); |
|---|
| 57 |
|
|---|
| 58 |
$id = mysql_real_escape_string($id); |
|---|
| 59 |
$access = mysql_real_escape_string($access); |
|---|
| 60 |
$data = mysql_real_escape_string($data); |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
$sql = "REPLACE |
|---|
| 64 |
|
|---|
| 65 |
; |
|---|
| 66 |
|
|---|
| 67 |
return mysql_query($sql, $_sess_db); |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
_destroy($id) |
|---|
| 71 |
|
|---|
| 72 |
$_sess_db, $wpdb; |
|---|
| 73 |
trace('destroying session data for $id', "$id"); |
|---|
| 74 |
$id = mysql_real_escape_string($id); |
|---|
| 75 |
|
|---|
| 76 |
$sql = "DELETE |
|---|
| 77 |
FROM $wpdb->sessions |
|---|
| 78 |
WHERE id = '$id'"; |
|---|
| 79 |
|
|---|
| 80 |
return mysql_query($sql, $_sess_db); |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
function _clean($max) |
|---|
| 84 |
{ |
|---|
| 85 |
global $_sess_db, $wpdb; |
|---|
| 86 |
|
|---|
| 87 |
$old = time() - $max; |
|---|
| 88 |
$old = mysql_real_escape_string($old); |
|---|
| 89 |
|
|---|
| 90 |
$sql = "DELETE |
|---|
| 91 |
|
|---|
| 92 |
; |
|---|
| 93 |
|
|---|
| 94 |
mysql_query($sql, $_sess_db); |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
?> |
|---|