Jump to content
Larry Ullman's Book Forums

Clarification On Setting Cookies

Recommended Posts

First let me say that I find your style of presentation and writing to be very effective.


With regard to the issue of making sure that cookies are sent before any header information I understand that the php code to send the cookies has to come before the header information. However, in your example for sending a cookie the first step is to see if the form has been submitted. As I understand the logic if the form has been submitted then the cookie is sent (using setcookie () ).

However, if the page has not loaded then the form cannot be set. This suggests that the cookie is sent after the page loads.


Based on the logic of the example my interpretation is that the following happens.

First comes the code to process the cookie

Then the page loads

Then when the user submits the form the page is reloaded and the cookie is sent.



Is that correct?



I'm trying to jump from your example to a simpler situation where I set a flag based on a parameter passed in the URL. In my case it seems that the first thing I have to do is to see if the flag had been previously set. I think this is done by opening the php with a

if (!isset ($_COOKIE['flag']) { }


Isn't it the case that all cookie code would want to open with a check to see if a cookie had previously been set?


Anyway, as you can tell I'm a neophyte stumbling around in the dark so any feedback would be appreciated.


Thanks, and once again I really like the way you present this topic. I think its very effective.

Link to comment
Share on other sites

Thanks for the nice words on the book. I appreciate it! It sounds like you're describing things properly, but I don't have the book next to me and want to double-check that page to confirm what I say on the reference page first.

Link to comment
Share on other sites

Thanks again for the nice words. I'm reviewing what I wrote and if I understand you correctly, you seem to have a good grasp of the topic. I wouldn't say, however, that all code wants to check if a cookie has already been set. That's just too blanket of a statement and certain situations imply alternative approaches.


Let me know if you have any other questions.

Link to comment
Share on other sites


  • Create New...