Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
mysql_connect('localhost','user','pass'); mysql_select_db('mydb'); function on_session_start($save_path, $session_name) { error_log($session_name . ' '. session_id()); } function on_session_end() { // Nothing needs to be done in this function // since we used persistent connection. } function on_session_read($key) { error_log($key); $stmt = 'SELECT session_data FROM sessions '; $stmt .= "WHERE session_id='$key' "; $stmt .= 'AND unix_timestamp(session_expiration) > unix_timestamp(date_add(now(),interval 1 hour))'; $sth = mysql_query($stmt); if($sth) { $row = mysql_fetch_array($sth); return($row['session_data']); } else { return $sth; } } function on_session_write($key, $val) { error_log("$key = $value"); $val = addslashes($val); $insert_stmt = "INSERT INTO sessions values('$key', "; $insert_stmt .= "'$val',unix_timestamp(date_add(now(), interval 1 hour)))"; $update_stmt = "UPDATE sessions SET session_data ='$val', "; $update_stmt .= "session_expiration = unix_timestamp(date_add(now(), interval 1 hour))"; $update_stmt .= "WHERE session_id ='$key '"; // First we try to insert, if that doesn't succeed, it means // session is already in the table and we try to update mysql_query($insert_stmt); $err = mysql_error(); if ($err != 0) { error_log( mysql_error()); mysql_query($update_stmt); } } function on_session_destroy($key) { mysql_query("DELETE FROM sessions WHERE session_id = '$key'"); } function on_session_gc($max_lifetime) { mysql_query("DELETE FROM sessions WHERE unix_timestamp(session_expiration) < unix_timestamp(now())"); } // Set the save handlers // This will make the session functions/variables use our functions instead. session_set_save_handler("on_session_start", "on_session_end", "on_session_read", "on_session_write", "on_session_destroy", "on_session_gc"); // Carry on as if you were normal session_start(); ?>
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)