I'm trying to use cookies for persistent login (that is, the user clicks a checkbox if they want a cookie to remember their login details for their next visit).
After they submit the login form, if they checked the remember box, I do something like this (if there login was correct):
if ($remember == 1)
{
$code = md5($pass);
setcookie ("LoginCookie[name]", $username, time() + 31104000, "", ".url.org");
setcookie ("LoginCookie[code]", $code, time() + 31104000, "", ".url.org");
}
I then set some session variables, and use a header("Location: menu.php") to move them to the menu page.
The problem is, the Cookies aren't really set. If I create an error on the page, so it has to reload, the cookies are set... but obviously, this isn't a workable solution.
I believe it has something to do with cookies being set when headers are passed. For some reason, the cookies aren't set when the header is redirected to the menu page.
How can I get my cookies to really set before moving on to the menu page after verifying the users login details?