Kristoff1875 Posted March 26, 2013 Share Posted March 26, 2013 I've got a login script, all working fine, but i've recently added a remember me cookie: $year = time() + 31536000; if($_POST['remember']) { setcookie('remember_me', $_POST['username'], $year); } elseif(!$_POST['remember']) { if(isset($_COOKIE['remember_me'])) { $past = time() - 100; setcookie(remember_me, gone, $past); } } All works fine on the normal login page, however, when clicking on the email link with url variables in it: login.php?clientid=1&jobid=1 It can't seem to pull the cookie that recalls the username and ticks the box. Anyone got any idea why this could be? Quote Link to comment https://forums.phpfreaks.com/topic/276191-session-cookies-with-url-variables/ Share on other sites More sharing options...
mac_gyver Posted March 26, 2013 Share Posted March 26, 2013 your setcookie isn't setting the path or domain parameters, so if you are changing the path or subdomain in the url, then your cookie won't match and won't be sent by the browser. Quote Link to comment https://forums.phpfreaks.com/topic/276191-session-cookies-with-url-variables/#findComment-1421226 Share on other sites More sharing options...
Kristoff1875 Posted March 27, 2013 Author Share Posted March 27, 2013 Should it be something like: $year = time() + 31536000; if($_POST['remember']) { setcookie('remember_me', $_POST['username'], $year, '/', '.mydomain.co.uk'); } elseif(!$_POST['remember']) { if(isset($_COOKIE['remember_me'])) { $past = time() - 100; setcookie(remember_me, gone, $past); } } Quote Link to comment https://forums.phpfreaks.com/topic/276191-session-cookies-with-url-variables/#findComment-1421404 Share on other sites More sharing options...
mac_gyver Posted March 27, 2013 Share Posted March 27, 2013 if that worked when you tried it, then yes. you must use the same path and domain parameters when you use the setcookie to clear the cookie, or it will actaully be trying to clear a different cookie. Quote Link to comment https://forums.phpfreaks.com/topic/276191-session-cookies-with-url-variables/#findComment-1421413 Share on other sites More sharing options...
Kristoff1875 Posted March 27, 2013 Author Share Posted March 27, 2013 It didn't work, that's why I asked haha Quote Link to comment https://forums.phpfreaks.com/topic/276191-session-cookies-with-url-variables/#findComment-1421419 Share on other sites More sharing options...
Kristoff1875 Posted March 27, 2013 Author Share Posted March 27, 2013 I have however just figured something out... login.php?clientid=1&jobid= sees the cookie fine... login.php?clientid=1&jobid=1 Doesn't see the cookie. Quote Link to comment https://forums.phpfreaks.com/topic/276191-session-cookies-with-url-variables/#findComment-1421420 Share on other sites More sharing options...
Solution Kristoff1875 Posted March 27, 2013 Author Solution Share Posted March 27, 2013 I feel like such an idiot now. Lets just say, one of the if statements, was causing this error.... nothing to see here!!!! Quote Link to comment https://forums.phpfreaks.com/topic/276191-session-cookies-with-url-variables/#findComment-1421422 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.