By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

Php session cookie

P: 2
I have this program created in PHP using MVC pattern.

I am using sessions for the program.

I am starting the session in bootstrap which is straight after the index.php

the session name is changed before starting session in bootstrap ... getting to the question after slight more info.

I wanted to know how to delete session cookie.

when someone logs in a session is created with specific name

when they logout I use this code to log the user out

Expand|Select|Wrap|Line Numbers
  1. class LogoutController
  2. {
  3.     public static function logout()
  4.     {
  5.         // Unset all of the session variables.
  6.         $_SESSION = array();
  7.  
  8.         // If it's desired to kill the session, also delete the session cookie.
  9.         // Note: This will destroy the session, and not just the session data!
  10.         if (ini_get("session.use_cookies")) 
  11.         {
  12.             $params = session_get_cookie_params();
  13.             setcookie(  session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]
  14.                      );
  15.         }
  16.         // Finally, destroy the session.
  17.         session_destroy();
  18.         header("location:login.php");
  19.     }
  20. }
  21. ?>
  22.  
when the user is relocated to the login.php page and the user logs in it creates another session cookie with the same name. I know this because I checked this on Mozilla firefox's cookie browser.

i dont know if I'm taking the right steps.

please help pplz
Mar 20 '12 #1
Share this Question
Share on Google+
1 Reply


helimeef
P: 77
Get rid of the if() statement, and just leave the code that's inside it. setcookie() is the only way to permanently delete session data, and your condition may not be getting evaluated as true.
Then, let us know if it worked or not.
Mar 26 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.