Jump to content

delete session cookie


Destramic

Recommended Posts

hey guys im using a session cookie to store a user_id, only if user has clicked to remember me on the login form...that way when autenticating it checks id in db and if matching a user it logs in automatically.

 

now the problem i want to just remove user_id from a session cookie.  if i use the code below to delete the user_id session then it will remove all session cookies.

 

 is there a way just to remove 1 session cookie?  thank you

// create session cookie
session_start();
session_set_cookie_params('3600', 'C:\Users\Ricky\Desktop\www\BiSi\private\tmp\session', 'http://127.0.0.1/', true, true);
ini_set('session.gc_probability', 1);
session['user_id'] = 1;

//delete session cookies
setcookie (session_name(), null, time() - 3600);
session_regenerate_id(true);

any help/advise would be greatful...cheers guys

 

Link to comment
Share on other sites

The data is not stored in the session cookie. The cookie only contains the session id.  PHP uses this to fetch the data from the session. All data stored in a session is stored on the server in the file system

 

To remove the user_id from the session you need to unset it from $_SESSION

unset($_SESSION['user_id']); // removes user_id from session

If you delete the actual session cookie, then all data in the session will be destroyed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.