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
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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.