coppermine-gallery.com/forum

Support => cpg1.6.x Support => cpg1.6 bridging => Topic started by: Lighting-Gallery on September 27, 2026, 07:58:23 PM

Title: SMF Session Verification Error on Logout Due to Serialization Handler Mismatch
Post by: Lighting-Gallery on September 27, 2026, 07:58:23 PM
I was attempting to set up a new Coppermine 1.6 installation bridged to our SMF 2.0.19 forum and hitting log out in CPG would always result in "Session verification failed.  Please try logging out and back in again, and then try again."  I tracked this down to a session serialization issue.  At some point SMF added @ini_set('session.serialize_handler', 'php_serialize') to their Load.php.  In CPG's smf20.inc.php _session_load() function it attempts to decode the session without specifying the handler.  This is usually going to be 'php' not 'php_serialize' and it will fail to deserialize the session.  As a result, it can't pass the session number value to SMF and it displays the error.  Adding the following to the start of _session_load() fixed the issue.

@ini_set('session.serialize_handler', 'php_serialize');
if (ini_get('session.serialize_handler') != 'php_serialize')
    @ini_set('session.serialize_handler', 'php');

I checked SMF 2.1 as well and although it does not display an error upon log out, CPG was still unable to deserialize the session data without it.  That might cause problems for anyone attempting to access SMF session variables within CPG.  It seems to me CPG should update the SMF bridge to deserialize using 'php_serialize'.

Title: Re: SMF Session Verification Error on Logout Due to Serialization Handler Mismatch
Post by: ron4mac on September 29, 2026, 01:41:01 PM
Thanks for the feedback (please consider posting a github issue in the future).

I don't currently have a SMF setup. Below is how I will change the relevant code:

function _session_load()
{
    $superCage = Inspekt::makeSuperCage();

    if ($superCage->cookie->keyExists('PHPSESSID')) {

        $session_id = $superCage->cookie->getEscaped('PHPSESSID');

        $sql = "SELECT data FROM {$this->sessionstable} WHERE session_id = '$session_id'";

        $result = $this->query($sql);

        if (cpg_db_num_rows($result)) {

            list($data) = cpg_db_fetch_row($result);
            if (substr($data, 0, 2) === 'a:') ini_set('session.serialize_handler', 'php_serialize');  //<-- added

            session_name('CPG');
            session_start();

            session_decode($data);

            $session = $_SESSION;

            return $session;
        }
        $result->free();
    }

    return false;
}

function _session_save($session)
{
    $superCage = Inspekt::makeSuperCage();

    if ($superCage->cookie->keyExists('PHPSESSID')) {

        $session_id = $superCage->cookie->getEscaped('PHPSESSID');

        $_SESSION = $session;

        $data = cpg_db_escape_string(session_encode());  //<-- changed

        $sql = "UPDATE {$this->sessionstable} SET data = '$data' WHERE session_id = '$session_id'";

        $this->query($sql);
    }
}

Could you please verify that it functions properly?
Title: Re: SMF Session Verification Error on Logout Due to Serialization Handler Mismatch
Post by: Lighting-Gallery on September 30, 2026, 02:51:05 AM
Yes, I tested that with SMF as-is and after removing their line that sets the serialization handler (so it reverts back to 'php' which older versions might use).  In both cases Coppermine successfully decoded the session.  Thank you.
Title: Re: SMF Session Verification Error on Logout Due to Serialization Handler Mismatch
Post by: ron4mac on September 30, 2026, 03:06:10 PM
Thanks. Changes will be in the 1.6.30 version.