Destramic Posted December 11, 2014 Share Posted December 11, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/293035-delete-session-cookie/ Share on other sites More sharing options...
Ch0cu3r Posted December 11, 2014 Share Posted December 11, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/293035-delete-session-cookie/#findComment-1499300 Share on other sites More sharing options...
jwwceo Posted December 11, 2014 Share Posted December 11, 2014 your session variables are not stored in the browsers cookies. Just a session ID, which your server uses to grab the related session variables. Quote Link to comment https://forums.phpfreaks.com/topic/293035-delete-session-cookie/#findComment-1499304 Share on other sites More sharing options...
Tom8001 Posted December 11, 2014 Share Posted December 11, 2014 // create session cookie session_start(); session['user_id'] = 1; Here you are not setting the user id try <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); session_start(); $_SESSION['user_id'] = 1; ?> Quote Link to comment https://forums.phpfreaks.com/topic/293035-delete-session-cookie/#findComment-1499336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.