How to check if sessions are enabled

What is the easiest way in PHP to determine if sessions are included in the php.ini file for a server. I want to pre-install for my PHP application and just need to check something.

+5
source share
3 answers
if (!extension_loaded('session')) {
    die('You must enable PHP session support for the system to work.');
}
+6
source

You can write a quick script:

<?php

// page1.php
session_start();
$_SESSION['my_index'] = "IT WORKED!";

Then on another page:

<?php
// page2.php
session_start();
echo $_SESSION['my_index'];

//output: IT WORKED
0
source
if ( ! function_exists('session_start')) die;
0
source

All Articles