Guest User

Untitled

a guest
Jun 7th, 2015
590
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.    function sqlses_open($save_path, $name) { return true; }
  4.    function sqlses_close() { return true; }
  5.  
  6.    function sqlses_checkid($id)
  7.    {
  8.       if (preg_match("{^[[:graph:]]{1,64}\$}",$id)) return true;
  9.       return false;
  10.    }
  11.  
  12.    function sqlses_encid($id)
  13.    {
  14.       if (!sqlses_checkid($id)) return;
  15.       $row=fetch_assoc(query("SELECT AES_ENCRYPT(\"nejaky string, furt stejny\", \"".escape($id)."\") as enc"));
  16.       return base64_encode($row['enc']);
  17.    }
  18.  
  19.    function sqlses_read($id)
  20.    {
  21.       if (!sqlses_checkid($id)) return;
  22.       $row=fetch_assoc(query("SELECT AES_DECRYPT(sessionData,\"".escape($id)."\") as enc FROM sessions WHERE id=\"".escape(sqlses_encid($id))."\" LIMIT 1"));
  23.       return (string) $row['enc'];
  24.    }
  25.  
  26.    function sqlses_write($id, $data)
  27.    {
  28.       if (!sqlses_checkid($id)) return;
  29.       query("REPLACE sessions SET id=\"".escape(sqlses_encid($id))."\", lastUpdate=NOW(), sessionData=AES_ENCRYPT(\"".escape($data)."\",\"".escape($id)."\")");
  30.       return affected_rows();
  31.    }
  32.  
  33.    function sqlses_destroy($id)
  34.    {
  35.       if (!sqlses_checkid($id)) return;
  36.       query("DELETE FROM sessions WHERE id=\"".escape(sqlses_encid($id))."\"");
  37.       return true;
  38.    }
  39.  
  40.    function sqlses_gc($maxlifetime)
  41.    {
  42.       query("DELETE FROM sessions WHERE lastUpdate &lt; NOW() - INTERVAL 24 HOUR");
  43.       return true;
  44.    }
  45.  
  46.    session_set_cookie_params(0);
  47.    session_set_save_handler("sqlses_open", "sqlses_close", "sqlses_read", "sqlses_write", "sqlses_destroy", "sqlses_gc");
  48.    session_start();
  49. ?>
RAW Paste Data