Hi 🙂 This is very strange — I am making the call:
setcookie("ApplicationUserRank", "test", mktime (0, 0, 0, 1, 1, time()+60*60*24*30));
And then, in another file, calling:
echo $_COOKIE["ApplicationUserRank"];
However, the echo is blank! I am not really sure what I am doing wrong here, anyone care to explain? 🙂
EDIT:
Following Richard’s suggestion, I ran the following code:
echo "COOKIE: " . $_COOKIE["ApplicationUserRank"];
Directly after setting the cookie. Still blank! Something seriously strange is happening.
EDIT to my EDIT:
Turns out, that re-runnign the code DOES display the cookie! I guess $_COOKIE does not load from setcookie commands. In fact now that I think about it, I read about that somewhere… Anyways, it would seem that the SAME web file is capable of reading these cookies… Just not any other cookies. (This all is of course after applying many fixes suggested below)
Trusting Tarek’s answer, and taking into consideration what rlemon says, it might prove useful to try the functions
ob_start()andob_end_flush(). They are output buffer controlling functions.As an example:
ob_start()andob_end_flush()are also necessary for implementing today’s fashions (like encryption) if you have no server-side support for it. Click here for further reading material.EDIT:
After reading Gumbo’s comment and checking PHP mktime’s page. Considering 9001 is an invalid year for UNIX,
mktime()would always return -1, thus deleting the cookie.A solution would be as follows: