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.