I'm making a login system. When a user logs in, it stores the username in a cookie. The problem is, the cookie isn't recognized as soon as its created, so if I have some code that relies on if (isset($_COOKIE['username']) ... it doesn't work until the user refreshes. I have the create-cookie code above this if-statement, but the cookie isn't actually stored until the page refreshes. Is this supposed to be how it works? Here is how I'm setting my cookie: setcookie('username', $username , time()+3600); Code (markup): Thanks in advance for any help... EDIT: That may have been confusing. To clarify it, the cookie isn't being stored until the page is refreshed. So if the page isn't refreshed, none of the code that relies on the cookie can be executed.
on the process page of the login you have to set the cookie - which is the first thing to do then store that cookie into a session from there $_SESSION['user'] = $_COOKIE['user'] Then when the user passes thru the system they are under a session variable, until it is destroyed. Either by logging out, or by closing the browser. But the great thing is that the cookie is set and when they go back to the login page, and if you have coded it properly - then they should see their login and password fields set. Hope this helps