1

I created a log out page and calling it through a href link but it not working the session was not destroying. Help me, the code n link are below.

logout.php

 <?php 
    session_start();
    session_unset();
    session_destroy();
    header("location:index.php"); 
 ?>
1

2 Answers 2

1
  1. Make sure the file is on same server.
  2. Write this code on the very top of everything else.
  3. Additionally use this code

    session_unset();
    session_write_close();
    
  4. session_destroy only destroys session on server end not the cookies, make sure you are not using cookies, if yes then see below code

To Set cookie

setcookie("cookieName", $value, time()+3600);  

To Unset Cookie

setcookie("cookieName", $value, time()-36000); 

More details about session: PHP: session_destroy - Manual

0

You probably need to regenerate the session ID:

session_regenerate_id();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.