Jump to content

Problem setting save handler


n14charlie

Recommended Posts

I want a custom code to be executed when a session times out (not destroyed) I googled it and found the idea to edit a "session_Set_handler" functions, the problem is when I even try to use the default ones as follow the session doesn't work anymore and I have no idea why (it works without the save_handler code)

Here's the code:

function open($save_path, $session_name)
                {
                  global $sess_save_path;

                  $sess_save_path = $save_path;
                  return(true);
                }

                function close()
                {
                  return(true);
                }

                function read($id)
                {
                  global $sess_save_path;

                  $sess_file = "$sess_save_path/sess_$id";
                  return (string) @file_get_contents($sess_file);
                }

                function write($id, $sess_data)
                {
                  global $sess_save_path;

                  $sess_file = "$sess_save_path/sess_$id";
                  if ($fp = @fopen($sess_file, "w")) {
                    $return = fwrite($fp, $sess_data);
                    fclose($fp);
                    return $return;
                  } else {
                    return(false);
                  }

                }

                function destroy($id)
                {
                  global $sess_save_path;

                  $sess_file = "$sess_save_path/sess_$id";
                  return(@unlink($sess_file));
                }

                function gc($maxlifetime)
                {
                  global $sess_save_path;

                  foreach (glob("$sess_save_path/sess_*") as $filename) {
                    if (filemtime($filename) + $maxlifetime < time()) {
                      @unlink($filename);
                    }
                  }
                  return true;
                }

                session_set_save_handler("open", "close", "read", "write", "destroy", "gc");
session_start(); 

 

any idea?

Link to comment
https://forums.phpfreaks.com/topic/168538-problem-setting-save-handler/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.