Login Full Code
// if login is ok then we add a cookie
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
//then redirect them to the members area
// if they are not logged in
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="username" maxlength="40">
<input type="password" name="pass" maxlength="50">
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
This script first checks to see if the login information is contained in a cookie on the users computer. If it is, it tries to log them in. If this is successful they are redirected to the members area.
If there is no cookie, it allows them to login. If the form has been submitted, it checks it against the database and if it was successful sets a cookie and takes them to the members area. If it has not been submitted, it shows them the login form.