Autofill username and password field
Posted: Thu Jan 07, 2010 11:48 am
I want to have a tick box on a log in system so when a user ticks it they are remembered on future visits. I've got it working through a cookie but I have run into one issue. When no cookie is set to start with the page displays an error stating the cookie doesn't exist. How can I get it to autofill the username and password fields only if the box has been ticked?
Here's the code for the tick box and cookie:
I know I need something in the second piece of code to only set the value if the cookie is set but I'm not sure how to do this.
Any ideas?
Thanks
Here's the code for the tick box and cookie:
Code: Select all
if (!empty($_POST['remember']));
{
setcookie("user", $userid, time()+3600);
setcookie("password", $password, time()+3600);
}
Code: Select all
echo '<tr><td>Username:</td>';
echo '<td><input type="text" name="userid" value='.$_COOKIE["user"].'></td></tr>';
echo '<tr><td>Password:</td>';
echo '<td><input type="password" name="password" value='.$_COOKIE["password"].'></td></tr>';
Any ideas?
Thanks