Why does a cookie fail to set?
I have a program like this:
if (Setcookie (' Me ', ' MyCookie '))
{
echo "Cookie has been set";
}
echo "Logged in";
The result of the run is "logged in" Yes, but "cookie is set" is not displayed. This indicates that the cookie setting failed.
May I ask why this section of the program is set to fail? Is there a grammatical error? What could be the cause of the failure? (My browser supports cookies)
Share to:
------Solution--------------------
Setcookie () defines a cookie that is sent along with the rest of the HTTP headers. Like other headers, a cookie must be sent before any other output from the script (this is a protocol restriction). This requires that the call to this function be placed before any output, including the label and any spaces. If there is any output before calling Setcookie (), this function will fail and return FALSE. Returns TRUE if the Setcookie () function runs successfully.