Sutlej Solutions

how to destroy all session variables in php?

how to destroy all session variables in php?

A PHP session can be destroyed using the sessions_destroy() function. It does not require any arguments and a single command can erase all session variables. If you’re looking to eliminate one session variable, you can use the unset() function . It will remove the session variable.

You can also try following code: use within php tag

 
    session_start();

    $helper = array_keys($_SESSION);
    foreach ($helper as $key){
        unset($_SESSION[$key]);
    }
 

For More stubborn Sessions we can try

session_start();
session_unset();
session_destroy();
session_write_close();
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);

About the author...

#Freelancer #Journalist. Writes on #Economy, #Finance, #Constitution and #Technology. Develops #OpenSource #Software in #php #JavaScript. A #Foodie for Life!

View all posts by Rana Mansoor Akbar Khan

Your reactions

Add your comment

Fields marked with * are mandatory

© 2022 Sutlej Solutions

Why Sutlej Solutions

A single source solution provider for your all Web and Mobile App requirements. We understand your needs and provide simple and intelligent solutions. Our TV Gadget Reviews Blog and Custom Built Online Store as good examples of our excellent work

Need an Online Shop?

We provide full service Online Shop and Website Development and Maintenance Services.

Contact us Now: +92313335999

Business Hours

Monday
9.00pm – 6.00pm
Tuesday
9.00pm – 6.00pm
Wednesday
9.00pm – 6.00pm
Thursday
9.00pm – 6.00pm
Friday
9.00pm – 6.00pm
Saturday
9.00pm – 6.00pm
Sunday
Closed
hire web development company