/sesiones.php
PHP | 66 lines | 55 code | 10 blank | 1 comment | 2 complexity | f0320cbb933b05b60d20cdbdbeca2ef1 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, MIT, LGPL-3.0, LGPL-2.1
- <?php
- mysql_connect("localhost", "phpuser", "alm65z");
- mysql_select_db("phpdb");
-
- function sess_open($sess_path, $sess_name) {
- return true;
- }
-
- function sess_close() {
- return true;
- }
-
- function sess_read($sess_id) {
- $result = mysql_query("SELECT Data FROM sessions WHERE SessionID = '$sess_id';");
- if (!mysql_num_rows($result)) {
- $CurrentTime = time();
- mysql_query("INSERT INTO sessions (SessionID, DateTouched) VALUES ('$sess_id', $CurrentTime);");
- return '';
- } else {
- extract(mysql_fetch_array($result), EXTR_PREFIX_ALL, 'sess');
- mysql_query("UPDATE sessions SET DateTouched = $CurrentTime WHERE SessionID = '$sess_id';");
- return $sess_Data;
- }
- }
-
- function sess_write($sess_id, $data) {
- $CurrentTime = time();
- mysql_query("UPDATE sessions SET Data = '$data', DateTouched = $CurrentTime WHERE SessionID = '$sess_id';");
- return true;
- }
-
- function sess_destroy($sess_id) {
- mysql_query("DELETE FROM sessions WHERE SessionID = '$sess_id';");
- return true;
- }
-
- function sess_gc($sess_maxlifetime) {
- $CurrentTime = time();
- mysql_query("DELETE FROM sessions WHERE DateTouched + $sess_maxlifetime < $CurrentTime;");
- return true;
- }
-
- session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc");
- session_start();
-
- $_SESSION['foo'] = "bar";
- $_SESSION['baz'] = "wombat";
- echo var_dump($_SESSION);
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <title> PHP session testing </title>
- <style type='text/css'>
- body { background-color: gray; }
- #content { background-color: white; width: 70%; margin: 1em auto 1em auto; padding: 2em;
- font-family: Verdana, monospace; font-size: 10pt; }
- </style>
- </head>
- <body>
-
- <div id='content'>
-
- </div>
- </body>
- </html>