villermen Posted July 8, 2009 Report Share Posted July 8, 2009 I've created a page to log someone out.The cookie:id that was created at the login will be deleted.The only problem is, it won't be deleted!The script: (I've changed the language so it is a bit more readable for you (it was in dutch)) <html><?phpif (isset($_COOKIE["id"])) { setcookie("id","",time()-1); $message="<p>You are now logged out.</p>"; //delete db entry }else $message="<p>You are already logged out!</p>";<head></head><body><?phpecho $message;?></body></html> Could it be the combination of isset(cookie) and the cookie itself inside it?Thanks.Villermen Link to comment Share on other sites More sharing options...
justsomeguy Posted July 8, 2009 Report Share Posted July 8, 2009 It's because you have the HTML tag before the PHP code, anything using setcookie needs to come before any other output. You're also missing a closing PHP tag there. Link to comment Share on other sites More sharing options...
villermen Posted July 8, 2009 Author Report Share Posted July 8, 2009 Whoops... I thought it was the head tag...I only forgot the closing tag in this script, not in the original.Thanks! Link to comment Share on other sites More sharing options...
villermen Posted July 8, 2009 Author Report Share Posted July 8, 2009 It still doesn't work??I placed it before the html tag, and after the doctype declaration. (before the doctype outputs the same)$message still outputs "<p>You are now logged out.</p>"the cookie isnt changed Link to comment Share on other sites More sharing options...
villermen Posted July 8, 2009 Author Report Share Posted July 8, 2009 I got it...I didn't know that you need to put the path into the function everytime you use the setcookie function with an already set cookiepath.I've fixed it now Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now