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
https://forums.phpfreaks.com/topic/293035-delete-session-cookie/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.