PHPverse 2025

Voting

: three minus two?
(Example: nine)

The Note You're Voting On

coder dot ua at gmail dot com
11 years ago
Universal function for checking session status.

<?php
/**
* @return bool
*/
function is_session_started()
{
if (
php_sapi_name() !== 'cli' ) {
if (
version_compare(phpversion(), '5.4.0', '>=') ) {
return
session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE;
} else {
return
session_id() === '' ? FALSE : TRUE;
}
}
return
FALSE;
}

// Example
if ( is_session_started() === FALSE ) session_start();
?>

<< Back to user notes page

To Top