Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9064785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:20:32+00:00 2026-06-16T16:20:32+00:00

I’m having issues with setting session_set_save_handler. I configured my php.ini to session.handler = user

  • 0

I’m having issues with setting session_set_save_handler. I configured my php.ini to session.handler = user

This simple test is failing:

//Define custom session handler
if(session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write",     "sess_destroy", "sess_gc")){
die('set fine');
}else{
die('Couldn\'t set session handler');

Here is my session class.

//Constructor
function __construct(){

//Define custom session handler
if(session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc")){
    die('set fine');
}else{
    die('Couldn\'t set session handler');
}

//Start session
session_start();
}


//Custom session functions
function sess_open($sess_path, $sess_name) {

return true;
}

function sess_close() {

return true;
}

function sess_read($sess_id) {

//Query for session record in
$results = $db->QuerySingleRow("SELECT data FROM sessions WHERE session_id = '$sess_id'");

//Check that record is returned
if ($results != false)
{
    //Session found, pull out data field value
    $sess_data = $results->data;

    //Grab current time
    $CurrentTime = time();

    //Update session record with current timestamp
    $db->Query("UPDATE sessions SET last_updated = $CurrentTime WHERE session_id = '$sess_id'");

    //Return 
    return $sess_data;
}
else
{
    //No session found

    //Grab current timestamp
    $CurrentTime = time();

    //Insert new session to DB
    $db->Query("INSERT INTO sessions (session_id, last_updated) VALUES ('$sess_id', $CurrentTime)");

    //Return blank per nature of session_set_save_handler read()
    return '';
}
}

function sess_write($sess_id, $data) {

//Grab current timestamp
$CurrentTime = time();

//Update session record to hold new data and update last_updated field
$db->Query("UPDATE sessions SET data = '$data', last_updated = $CurrentTime WHERE session_id = '$sess_id'");

return true;
}

function sess_destroy($sess_id) {

//Delete session from DB
$db->Query("DELETE FROM sessions WHERE session_id = '$sess_id'");

return true;
}

function sess_gc($sess_maxlifetime) {

//Get current timestamp
$CurrentTime = time();

//Delete from session based on garbage collection
$db->Query("DELETE FROM sessions WHERE last_updated < $CurrentTime");

return true;
}


}

The only thing I can think of is $db is an suppose to be an object of my MySQL DB class but I can’t include the class and then create an instance of it.

I didn’t want to reinvent the wheel on the DB class so I grabbed it from Jeff Williams here: http://www.phpclasses.org/package/3698-PHP-MySQL-database-access-wrapper.html

I’ve tried to include it out side the class body put then the page doesn’t render, just a blank white page no errors.:

<?php
include 'mysql.class.php';
$db = new MySQL(true);

class session
{

//Constructor
function __construct(){
....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:20:33+00:00Added an answer on June 16, 2026 at 4:20 pm

    Setting the session save handler fails:

    session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc")
    

    Because these callbacks you want to register to do not exists:

    var_dump(is_callable("sess_open")); # FALSE
    

    That is because your object methods needs to be properly registered as callbacks. An object method callback is written in form of an array with two elements, the first one is the object, the second one a string of the methodname. Example from PHP net that is similar to yours:

    $handler = new FileSessionHandler();
    session_set_save_handler(
        array($handler, 'open'),
        array($handler, 'close'),
        array($handler, 'read'),
        array($handler, 'write'),
        array($handler, 'destroy'),
        array($handler, 'gc')
    );
    

    As you can see, each method is written as a single array with the first element $handler always.

    From within the class you can use $this to refer to the same object. But before your fully write your own, check the session_set_save_handler() PHP manual page for infos, examples and user contributed notes. There are different ways how you can organize that for your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.