Jump to content

[SOLVED] Newbie struggling


nibbo

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.