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? 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. 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); } } 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. 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 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. Link to comment https://forums.phpfreaks.com/topic/276191-session-cookies-with-url-variables/#findComment-1421420 Share on other sites More sharing options...
Kristoff1875 Posted March 27, 2013 Author 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!!!! 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
Archived
This topic is now archived and is closed to further replies.