PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/sesiones.php

https://bitbucket.org/weddcam/develop_weddcam
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
  1. <?php
  2. mysql_connect("localhost", "phpuser", "alm65z");
  3. mysql_select_db("phpdb");
  4. function sess_open($sess_path, $sess_name) {
  5. return true;
  6. }
  7. function sess_close() {
  8. return true;
  9. }
  10. function sess_read($sess_id) {
  11. $result = mysql_query("SELECT Data FROM sessions WHERE SessionID = '$sess_id';");
  12. if (!mysql_num_rows($result)) {
  13. $CurrentTime = time();
  14. mysql_query("INSERT INTO sessions (SessionID, DateTouched) VALUES ('$sess_id', $CurrentTime);");
  15. return '';
  16. } else {
  17. extract(mysql_fetch_array($result), EXTR_PREFIX_ALL, 'sess');
  18. mysql_query("UPDATE sessions SET DateTouched = $CurrentTime WHERE SessionID = '$sess_id';");
  19. return $sess_Data;
  20. }
  21. }
  22. function sess_write($sess_id, $data) {
  23. $CurrentTime = time();
  24. mysql_query("UPDATE sessions SET Data = '$data', DateTouched = $CurrentTime WHERE SessionID = '$sess_id';");
  25. return true;
  26. }
  27. function sess_destroy($sess_id) {
  28. mysql_query("DELETE FROM sessions WHERE SessionID = '$sess_id';");
  29. return true;
  30. }
  31. function sess_gc($sess_maxlifetime) {
  32. $CurrentTime = time();
  33. mysql_query("DELETE FROM sessions WHERE DateTouched + $sess_maxlifetime < $CurrentTime;");
  34. return true;
  35. }
  36. session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc");
  37. session_start();
  38. $_SESSION['foo'] = "bar";
  39. $_SESSION['baz'] = "wombat";
  40. echo var_dump($_SESSION);
  41. ?>
  42. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
  43. <html>
  44. <head>
  45. <title> PHP session testing </title>
  46. <style type='text/css'>
  47. body { background-color: gray; }
  48. #content { background-color: white; width: 70%; margin: 1em auto 1em auto; padding: 2em;
  49. font-family: Verdana, monospace; font-size: 10pt; }
  50. </style>
  51. </head>
  52. <body>
  53. <div id='content'>
  54. </div>
  55. </body>
  56. </html>