Why are my cookies not setting?

try adding the path = /, so that the cookie works for the whole site not just the current directory (that has caught me out before)

example

setcookie('password',$password,time()+60*60*24*365, "https://stackoverflow.com/"); 

also make sure the cookie is the first thing being output
as advised in the php manual (this has caught me out before too)

Like other headers, cookies must be sent before any output from your
script (this is a protocol restriction).

Leave a Comment