FrostedFlakes1024 Posted August 25, 2010 Share Posted August 25, 2010 For some reason I can not get this to work. Any thoughts? if( $row['password'] == $pass && $row['name'] == $user ) { $username = $row['name']; $uid = $row['id']; setcookie("id", $uid, 1400); //creates the first session var setcookie("username", $username, 1400); // second session var setcookie("loggedin", "1", 1400); echo "<script type=\"text/javascript\">alert(\"".$row['name']."Logged in as ".$_COOKIE['username'].".\"); window.location=\"index.php?OMG=loggedin\"</script>"; } I get a message box saying: "[username] Logged in as ." I've searched php.ini for corrupt cookie settings, nothing unusual. Quote Link to comment https://forums.phpfreaks.com/topic/211696-setcookie-help/ Share on other sites More sharing options...
MadTechie Posted August 25, 2010 Share Posted August 25, 2010 1. cookies are read from the header 2. setting cookie goes into the header (hence before any output) 3. expire is a unix DATE & time (not just seconds) if( $row['password'] == $pass && $row['name'] == $user ) { $username = $row['name']; $uid = $row['id']; setcookie("id", $uid, time()+1400); //creates the first session var setcookie("username", $username, time()+1400); // second session var setcookie("loggedin", "1", time()+1400); //Cookie won't be set visible until a the header loads (next page) echo "<script type=\"text/javascript\">alert(\"".$row['name']."Logged in as ".$username.".\"); window.location=\"index.php?OMG=loggedin\"</script>"; } Quote Link to comment https://forums.phpfreaks.com/topic/211696-setcookie-help/#findComment-1103551 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.