-1

Basically this is the part of the code I used

<?php //PHP Start
// session_destroy();
session_start();
$var1 = 'why';
$_SESSION['produk'] = array(); //session produk jadi array (untuk data penjualan)
$_SESSION['counter'] = $var1;
$_SESSION['variable1'] = 'not working';
?>

When I used this code, I got the ini_set() error, and I just can't solve the problem so I thought of just destroying all session and just make a new one, but after I uncomment the session_destroy() I just got a new error

session_destroy(): Trying to destroy uninitialized session

So apparently I don't have any active session even though session_start() got an error saying session is active? What is going on here?

I also tried placing this on the session_start() from Message: ini_set(): A session is active. You cannot change the session module's ini settings at this time but didn't work

if (!isset($_SESSION)) {

// server should keep session data for AT LEAST 24 hour
ini_set('session.gc_maxlifetime', 60 * 60 * 24);

// each client should remember their session id for EXACTLY 24 hour
session_set_cookie_params(60 * 60 * 24);
session_start();
}
Dragonarc
  • 73
  • 2
  • 10

1 Answers1

0

I know that sessions can be a little bit messy sometimes. This is also due to the fact that sessions are managed differently depending on the PHP version you are running. I personnaly always use this :

function sess_start(){
        try{
            if(version_compare(phpversion(),'5.4.0','<')){
                if(session_id() == '') {
                    session_start();
                }
            }else{
                if (session_status() === PHP_SESSION_NONE) {
                    session_start();
                }
            }
            return true;
        }catch(Exception $e){
            return false;
        }
        
    }

Tell me if it worked fine for you.