nibbo Posted December 27, 2007 Share Posted December 27, 2007 Hi all; hope you can help me. I have a login page which uses cookies to support the usual 'remember me' function. The problem is that the cookies seem to dissapear as soon as the browser is closed. I am using PHP 5 with Apache 2.2. Here is a cut down version of the login page: <?php ob_start(); if ($_POST['Remember']) { $cookie = setcookie('user', $_POST['userid'], mktime().time()+(60*60*24*90), "/"); } ?> <html><head><title>Logon</title></head><body><form name="LogOn" action="<?php echo $_POST['PHP_SELF']?>" method="post"> <?php if (isset($_COOKIE['user'])) { echo "welcome back " . $_COOKIE['user']; } else { echo "user cookie not set"; } ?> <br>Input name: <input type='text' name='userid'> <br>Remember me? <input type='checkbox' name='Remember'> <br><input type='submit'> </form></body></html> I am sure it is something obvious; thanks in advance. Link to comment https://forums.phpfreaks.com/topic/83320-solved-newbie-struggling/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 27, 2007 Share Posted December 27, 2007 mktime().time()+(60*60*24*90) results in a string of numbers that is not a valid Unix time stamp that php expects for the expire parameter. It is basically two concatenated Unix time stamps that treated as a value is meaningless. You should probably read the definition of the expire parameter and the examples in the manual - http://php.net/setcookie Link to comment https://forums.phpfreaks.com/topic/83320-solved-newbie-struggling/#findComment-423887 Share on other sites More sharing options...
nibbo Posted December 27, 2007 Author Share Posted December 27, 2007 Thanks a lot; I actiually cut & pasted the expiry formula from the page you suggested but did not realise the mktime. bit was a seperate sentence. Oooops. Now working OK. Link to comment https://forums.phpfreaks.com/topic/83320-solved-newbie-struggling/#findComment-423916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.