Jump to content

Unexplainable Cookie Problem


Flowlance

Recommended Posts

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":

 

cookie1d.jpg

 

Here's the same code a few lines down, cookie is not being set and returns "Not set":

 

cookie2.jpg

 

 

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 :P

Link to comment
https://forums.phpfreaks.com/topic/257425-unexplainable-cookie-problem/
Share on other sites

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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.