Logical1 Posted May 17, 2009 Share Posted May 17, 2009 I am trying to make a log in/log off for my site I have problems with logging off. I want to set cookies (username) for duration of session and clear it when they log off. I can resigster a session and set cookie by this code: session_start(); session_name("H1000"); session_register("LUN"); setcookie("LUN",$_POST["N1"],0, "/","www.123xyz.com",0); So far so good. Problem is that no matter what I try I can not get rid of the username cookie when I try to log off (I can still see the name on pages after I try to log off). To log off this is the code: <?php session_start(); $_SESSION = array(); setcookie(session_name(H1000), '$LUN', time()-42000, '/'); session_destroy(); header('Location:index.php'); ?> Can somebody tell me what am I doing wrong? Thanks in advance. L1 Quote Link to comment https://forums.phpfreaks.com/topic/158509-ending-a-session-and-deleting-cookies/ Share on other sites More sharing options...
Masna Posted May 17, 2009 Share Posted May 17, 2009 Because of how you're setting the cookies, it looks as if they'll never be set long enough to be deleted. setcookie("HCC","1",0, "/","www.123.com",0); The third parameter here is the date of expiration as a UNIX timestamp. You have 0, so, if I'm not mistaken, the cookie is deleted as it's set. Try this: setcookie("HCC","1", time()+42000, "/","www.123.com",0); Quote Link to comment https://forums.phpfreaks.com/topic/158509-ending-a-session-and-deleting-cookies/#findComment-835949 Share on other sites More sharing options...
MadTechie Posted May 17, 2009 Share Posted May 17, 2009 Shouldn't killing it be more like this <?php session_start(); $_SESSION = array(); setcookie(session_name("H1000"), '', time()-42000, '/'); setcookie(session_name("LUN"), '', time()-42000, '/'); session_destroy(); header('Location:index.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/158509-ending-a-session-and-deleting-cookies/#findComment-835952 Share on other sites More sharing options...
Logical1 Posted May 17, 2009 Author Share Posted May 17, 2009 I don't follow you. If the cookie was deleted then after logging in I should not be able to see username (which I do). (Also I was editing the question when you answered please look at it now). Can somebody write or point to an example code where session is registed and one cookie is set and then in a secondary page session is ended and cookie cleared? I have been going over php.net and many forums to see examples and tried at least a dozen of them. Bless their hearts, often they don't try their code before posting it. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/158509-ending-a-session-and-deleting-cookies/#findComment-835955 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.