What is the purpose of the cookie for you? Do you intend to keep someone logged in for days/weeks?
Full PHP authentication system.
Login.php:
PHP Code:
<?php
session_start();
if (!empty($_POST)) {
if ($_POST['username'] == 'something' && $_POST['password'] == 'something') {
$_SESSION['username'] = $_POST['username'];
header("Location: member.php");
exit;
}
}
?>
<form action="login.php" method="post">
Username: <input type="text" name="username" value="" /><br />
Password: <input type="password" name="password" value="" /><br />
<input type="submit" value="Log in" />
</form>
And at the top of any page you want to require a login for:
PHP Code:
<?php
session_start();
if (!isset($_SESSION['username'])) {
header("Location: login.php");
exit;
}
//rest of the now-protected page
Just fill in the details, like looking up the username/password in a database if you're using one, and where to redirect upon logging in.
Bookmarks