Reputation: 3848
This is the very simple code I am using to set a cookie in PHP:
setcookie("vgc_email", $userinfo['email']) or emsg("Unable to set cookie");
Error_reporting is set to E_ALL and is not giving an error, however, Unable to set cookie
is given when I attempt to run this code, and no cookie is set. I have made sure that $userinfo['email']
is not empty. I am also sure that I am able to receive cookies, when using Facebook connect is has set a cookie on the website.
So why won't this one work?
Upvotes: 0
Views: 133
Reputation: 449783
From the manual:
If output exists prior to calling this function, setcookie() will fail and return FALSE. If setcookie() successfully runs, it will return TRUE. This does not indicate whether the user accepted the cookie.
so most likely, you are outputting data before calling setcookie()
.
Upvotes: 3
Reputation: 17333
Check if the headers were sent before setting a cookie with headers_sent()
Upvotes: 1