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
    refer this http://stackoverflow.com/questions/1226040/is-this-a-proper-way-to-destroy-all-sessions-in-php – Sibu Nov 08 '12 at 05:11

2 Answers2

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

sachleen
  • 30,730
  • 8
  • 78
  • 73
0

You probably need to regenerate the session ID:

session_regenerate_id();

Ben
  • 54,723
  • 49
  • 178
  • 224