Flowlance Posted February 21, 2012 Share Posted February 21, 2012 Alright so I have coded a login system, and logging in works. But I just noticed that logging out did not work. I tried making a test cookie at the very top of my document, and it worked. I couldn't find out why, because there's really nothing in between than can be causing it. I tried moving the code down line by line until it stopped working, it happened after a block of html code. Makes no sense to me at all. Here's the working code, it sets the cookie and returns "Set": Here's the same code a few lines down, cookie is not being set and returns "Not set": Why? XD I tried removing that entire div-block but then the code would just stop working a bit further down in my document. It's a challenge to you, phpfreaks Link to comment https://forums.phpfreaks.com/topic/257425-unexplainable-cookie-problem/ Share on other sites More sharing options...
jcbones Posted February 21, 2012 Share Posted February 21, 2012 setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. Headers MUST come before any output. Link to comment https://forums.phpfreaks.com/topic/257425-unexplainable-cookie-problem/#findComment-1319401 Share on other sites More sharing options...
Flowlance Posted February 21, 2012 Author Share Posted February 21, 2012 I see, that's probably it. Weird that it worked at certain places after headers though Link to comment https://forums.phpfreaks.com/topic/257425-unexplainable-cookie-problem/#findComment-1319408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.