Kasyx
Kasyx

Reputation: 3200

Check if write session in blocked

Php provides function session_write_close. I want to check if session has been closed. session_id() still returns value.

session_start();

//
// Some code there
//

session_write_close();

//
// Some code there
//

if( /*is session write closed?*/)
    echo 'Session closed';
else
    echo 'Session still opened';

Upvotes: 1

Views: 509

Answers (2)

Baba
Baba

Reputation: 95151

All you need is

session_start();
session_write_close();
var_dump(sessionStatus()); // this would return false 

And

session_start();
var_dump(sessionStatus()); // true

Function Used

function sessionStatus() {
    if (function_exists('session_status')) {
        return (session_status() == PHP_SESSION_ACTIVE);
    }
    return defined('SID');
}

Upvotes: 2

complex857
complex857

Reputation: 20753

If you have PHP version 5.4.0 or greater, you can use session_status().

Upvotes: 1

Related Questions