473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Php session cookie

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
1 1612
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

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

Similar topics

7
by: Henry Hartley | last post by:
I've got a PHP system working on a development server (Windows 2000/IIS5/PHP 4.3.3) but it doesn't seem to be working quite right on the testing server (same except PHP 4.2.3). I upgraded the PHP...
1
by: Matt | last post by:
I want to know what's the differences between session cookie and regular cookie. In ASP, when we create cookie, we do the following to identify an user: Response.Cookies("name") = value Is...
3
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change...
5
by: Yossi | last post by:
I want to set the asp session id path property. how can I do that? I mean, asp session id is stored in a cookie and like any other cookie it should have properties (or attributes), how can I...
3
by: Karsten Grombach | last post by:
Hi, I'm trying the following: - Imitate a Logon using a Post with HttpWebRequest on remote Webserver (asp 3.0 page using https) - On success redirect to the page (encapsuled in an iframe)...
2
by: Earl Teigrob | last post by:
I am trying to find storage mechanism that will store a variable until the browser window is closed. A query string variable would be my first choice for this but that is not easily done in my...
1
by: Daniel Michaeloff | last post by:
Hi all, I have an application that when finished redirects to a non-ASP.NET app which is choking on a huge ASP.NET session cookie. The cookie "ASP.NET_SessionId" gets transmitted by the browser...
7
by: Doug | last post by:
An ASP.NET session cookie set on "www.mydomain.com" can not be accessed on "search.mydomain.com"; hence, a new session and cookie are being created on every sub-domain. This is occuring because...
4
by: nico | last post by:
I store the authenticated user in a session cookie. This cookie expires after an hour. Now for some reason sometimes the client browser decides not to send the session cookie information with a new...
4
by: Ibrahim. | last post by:
Hi, Kindly clarify the followings; 1. Is the session cookie & FormsAuthenticationTicket cookie Interdependent? 2. When a new SessionID is generated, I have noticed the Session Cookie and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.