Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function sqlses_open($save_path, $name) { return true; }
- function sqlses_close() { return true; }
- function sqlses_checkid($id)
- {
- if (preg_match("{^[[:graph:]]{1,64}\$}",$id)) return true;
- return false;
- }
- function sqlses_encid($id)
- {
- if (!sqlses_checkid($id)) return;
- $row=fetch_assoc(query("SELECT AES_ENCRYPT(\"nejaky string, furt stejny\", \"".escape($id)."\") as enc"));
- return base64_encode($row['enc']);
- }
- function sqlses_read($id)
- {
- if (!sqlses_checkid($id)) return;
- $row=fetch_assoc(query("SELECT AES_DECRYPT(sessionData,\"".escape($id)."\") as enc FROM sessions WHERE id=\"".escape(sqlses_encid($id))."\" LIMIT 1"));
- return (string) $row['enc'];
- }
- function sqlses_write($id, $data)
- {
- if (!sqlses_checkid($id)) return;
- query("REPLACE sessions SET id=\"".escape(sqlses_encid($id))."\", lastUpdate=NOW(), sessionData=AES_ENCRYPT(\"".escape($data)."\",\"".escape($id)."\")");
- return affected_rows();
- }
- function sqlses_destroy($id)
- {
- if (!sqlses_checkid($id)) return;
- query("DELETE FROM sessions WHERE id=\"".escape(sqlses_encid($id))."\"");
- return true;
- }
- function sqlses_gc($maxlifetime)
- {
- query("DELETE FROM sessions WHERE lastUpdate < NOW() - INTERVAL 24 HOUR");
- return true;
- }
- session_set_cookie_params(0);
- session_set_save_handler("sqlses_open", "sqlses_close", "sqlses_read", "sqlses_write", "sqlses_destroy", "sqlses_gc");
- session_start();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement