Bramme Posted May 18, 2007 Share Posted May 18, 2007 Okay, so I'm working on a little project, and I've got a little loginbox, it has a checkbox, just like vbulletin, to keep you logged in(set a cookie) or just use a $_SESSION... So here's how my login script looks: <?php // Log in $loginname = isset($_POST['usname']) ? $_POST['usname'] : ""; $loginpass = isset($_POST['passw']) ? $_POST['passw'] : ""; $loginpass = md5($loginpass); $remember = isset($_POST['remember']); if(!empty($loginname) && !empty($loginpass)) { $c = mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE name = '$loginname' AND password = '$loginpass'")); if($c > 0) { if($remember == TRUE) { setcookie("usname", $loginname, time()+(7*86400)); setcookie("pass", $loginpass, time()+(7*86400)); } else { $_SESSION['loggedin'] = $loginname; } } } header("Location: /play/game/"); ?> Now, I soon noticed that i wasn't logging in when using cookies (session works fine), so I decided to echo the cookies in my index.php // Log in check: if(isset($_SESSION['loggedin']) || isset($_COOKIE['usname'])) { ... //i've tried combinations of isset and !empty, no difference } // testing if they are set in index.php echo 'usname: '.@$_COOKIE['usname'].'<br />'; echo 'pass: '.@$_COOKIE['pass'].'<br />'; echo 'session: '.@$_SESSION['loggedin'].'<br />'; and the cookies all return zip... So i thought there must be something wrong with the way i'm setting these cookies... However, when i had a look at my cookies (with mozilla firefox) i soon saw that they were perfectly set... I've got a cookie usname, with the username, and a cookie pass, but the website doesn't recognize them for some reason... other way around, when I log out <?php // Logout setcookie("usname",""); setcookie("pass",""); session_destroy(); header("Location: /read/home/"); ?> the cookies stay, right were they are... I haven't got a clue what's going on... I first thought it had something to do with the way I included my login page, but I've tried different things and none work... Quote Link to comment https://forums.phpfreaks.com/topic/51969-weird-setcookie-problem/ Share on other sites More sharing options...
jitesh Posted May 18, 2007 Share Posted May 18, 2007 setcookie("usname","",false,"/"); setcookie("pass","",false,"/"); Quote Link to comment https://forums.phpfreaks.com/topic/51969-weird-setcookie-problem/#findComment-256163 Share on other sites More sharing options...
Bramme Posted May 18, 2007 Author Share Posted May 18, 2007 nope... didn't do anything, doesn't even delete the cookies when logging out... Quote Link to comment https://forums.phpfreaks.com/topic/51969-weird-setcookie-problem/#findComment-256165 Share on other sites More sharing options...
jitesh Posted May 18, 2007 Share Posted May 18, 2007 When loggin out run following code to delete cookies. setcookie("usname","",time()-3600); setcookie("pass","",time()-3600); Quote Link to comment https://forums.phpfreaks.com/topic/51969-weird-setcookie-problem/#findComment-256178 Share on other sites More sharing options...
Bramme Posted May 18, 2007 Author Share Posted May 18, 2007 nope, doesn't work either, they just remain there... i'll upload all the files used, so if anyone would have some spare time, they could have a look at it... edit: http://bramme.net/cosmosw/ those are the files you can see it live here: http://bramme.net/cosmoswars/ the username and password are both "demo" Quote Link to comment https://forums.phpfreaks.com/topic/51969-weird-setcookie-problem/#findComment-256181 Share on other sites More sharing options...
jitesh Posted May 18, 2007 Share Posted May 18, 2007 <?php // Logout setcookie("usname","",time()-3600); setcookie("pass","",time()-3600); ------------------------------------- //////// Check here do you found set cokkies here echo "<pre>"; print_r($_COKKIE); exit; ------------------------------------- session_destroy(); header("Location: /read/home/"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51969-weird-setcookie-problem/#findComment-256186 Share on other sites More sharing options...
Bramme Posted May 18, 2007 Author Share Posted May 18, 2007 http://www.bramme.net/cosmoswars/log/out/ there you go... apparently he sees only one, however: (it's dutch, but you can still see the two cookies...) Quote Link to comment https://forums.phpfreaks.com/topic/51969-weird-setcookie-problem/#findComment-256189 Share on other sites More sharing options...
jitesh Posted May 18, 2007 Share Posted May 18, 2007 In Array you do not found the cookies "usname" and "pass" that means they are not exists. Clear all cookie from browser set previously. Then Run your script. Quote Link to comment https://forums.phpfreaks.com/topic/51969-weird-setcookie-problem/#findComment-256190 Share on other sites More sharing options...
Bramme Posted May 18, 2007 Author Share Posted May 18, 2007 tried that, no difference... the cookies get set, but not read, nor deleted... Quote Link to comment https://forums.phpfreaks.com/topic/51969-weird-setcookie-problem/#findComment-256193 Share on other sites More sharing options...
Bramme Posted May 18, 2007 Author Share Posted May 18, 2007 sorry for bumping, but i'm really stuffed with this problem... anyone an idea? Quote Link to comment https://forums.phpfreaks.com/topic/51969-weird-setcookie-problem/#findComment-256433 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.