perezf Posted September 11, 2006 Share Posted September 11, 2006 how can i have a user logout after they log ini am using cookies Quote Link to comment https://forums.phpfreaks.com/topic/20440-how-do-i-make-a-logout-solved/ Share on other sites More sharing options...
gijew Posted September 11, 2006 Share Posted September 11, 2006 From the manual...<?php// set the expiration date to one hour agosetcookie ("TestCookie", "", time() - 3600);setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".example.com", 1);?> For more info, [url=http://us3.php.net/manual/en/function.setcookie.php]http://us3.php.net/manual/en/function.setcookie.php[/url] Quote Link to comment https://forums.phpfreaks.com/topic/20440-how-do-i-make-a-logout-solved/#findComment-90080 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 can some one make that in to a link for me so the user can click Quote Link to comment https://forums.phpfreaks.com/topic/20440-how-do-i-make-a-logout-solved/#findComment-90081 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 i dont really understand that Quote Link to comment https://forums.phpfreaks.com/topic/20440-how-do-i-make-a-logout-solved/#findComment-90082 Share on other sites More sharing options...
AndyB Posted September 11, 2006 Share Posted September 11, 2006 [code]<a href="logout.php">Log out</a>[/code]And look at gijew's code and/or read the setcookie link offered in the same post to write the one line php script for logout.php Quote Link to comment https://forums.phpfreaks.com/topic/20440-how-do-i-make-a-logout-solved/#findComment-90087 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 so look here is my code to make the cookie now how do i unset it so i can logout [code] $cookie_name = "auth"; $cookie_value = "ok"; $cookie_expire = "0"; $cookie_domain = "2fr3sh.com"; setcookie($cookie_name, $cookie_value, $cookie_expire, "/", $cookie_domain, 0);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20440-how-do-i-make-a-logout-solved/#findComment-90090 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 i tried what you guys said and it didnt work ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/20440-how-do-i-make-a-logout-solved/#findComment-90092 Share on other sites More sharing options...
HuggieBear Posted September 11, 2006 Share Posted September 11, 2006 perezf...Just use the same code you had in your previous post that I just helped you with.All you need to do is set the cookie expire to sometime in the past...$cookie_expire = time()-1;As for a link, stick the cookie code in a seperate file with a header redirect at the bottom, and then link to it normally.RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/20440-how-do-i-make-a-logout-solved/#findComment-90093 Share on other sites More sharing options...
perezf Posted September 11, 2006 Author Share Posted September 11, 2006 Worked Perfectly Thank you so much HuggieBear Quote Link to comment https://forums.phpfreaks.com/topic/20440-how-do-i-make-a-logout-solved/#findComment-90096 Share on other sites More sharing options...
gijew Posted September 11, 2006 Share Posted September 11, 2006 I'm trying to work up some good charma so someone can help me out in another post so let me explain that one line of code = )setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".example.com", 1);setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure [, bool httponly]]]]]] )The first line is a copy/paste from above. The second line is another copy/paste from the manual telling you what goes in the function.So this is how the first function works... - "TestCookie" = string name or the name of the cookie. - "" = blank. I believe if you're trying to delete a portion of the cookie (I don't really use them so I'm not positive). - time() - 3600 = This is setting the time backwards so the browser will delete the cookie. - "/~rasmus/" = the path you are deleting from (Optional) - "example.com" = the domain you are deleting from (Optional) - 1 = If the site is secure or not (Optional)To sum that up, just make sure to have the cookie name (which you have when you create the cookie) and the time is required as well to delete it. Follow the first example. Copy and paste it, change out the name for your cookie and BAM. That last sentence says it all! Quote Link to comment https://forums.phpfreaks.com/topic/20440-how-do-i-make-a-logout-solved/#findComment-90099 Share on other sites More sharing options...
HuggieBear Posted September 11, 2006 Share Posted September 11, 2006 I have the following code which both sets and 'unsets' a cookie... If you call cookie.php?status=logout then you get the cookie unset, if you call it with cookie.php?status=login then the cookie gets set.[code=php:0]<?php// Cookie parameters $cname = "auth"; $cvalue = "yes"; $cpath = "/"; $cdomain = "xxxxxx.co.uk"; $cexpire = (isset($_GET['status'] == "logout") ? time()-3600 : time()+3600; // Ternary to see if we're setting or unsetting setcookie($cname, $cvalue, $cexpire, $cpath, $cdomain); // Now we've set the cookie, lets direct to a page that uses it. header("Location: index.php");?>[/code]And before anyone says anything, I'm aware that you could pass any value other than 'logout' as an argument to cookie and it would set the cookie. I just cobbled it together quickly to show how simple it is.RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/20440-how-do-i-make-a-logout-solved/#findComment-90101 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.