i'm using this article in the joke site. So i've the site ok, and then i protected the pages with the accesscontrol file include. Now, i had this idea: add a check box so that the user can add a cookie with username+passord to remember.
the code: (in the accesscontrol.php include)
PHP Code:
<form method="post" action="<?=$PHP_SELF?>">
<table>
<tr>
<td align="right">Nome:</td>
<td><input type="text" name="uid" size="8"></td>
</tr>
<tr>
<td align="right">Palavra passe:</td>
<td><input type="password" name="pwd" SIZE="8"></td>
</tr>
<tr><td align="right">Guardar os meus dados</td> <td><input type="checkbox" name="cookieuser" unchecked /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Login"></td>
</tr>
</table>
</form>
Then, at the top of the same file, i have:
PHP Code:
<!--accesscontrol.php-->
<?php session_start();
$checkbox=$_POST['cookieuser'];
if (isset($checkbox)) {
$expiry = 60*60*24*365;
setcookie('uid', $uid, time()+$expiry, "/");
setcookie('pwd', $pwd, time()+$expiry, "/");
}
$uid=(isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid']);
$pwd=(isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd']);
include("common.php");
include("db.php");
...
What is happening is that, IF the user CHECKS the checkbox, then when she changes page, the script looses her ID!
(i've another include that welcomes the user with her username (id)).
If the checkbox is not checked, then everything is ok.
What's happening?
Bookmarks