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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.