Password Protect Follow-up
In this tutorial, I'm going to work off kane0ner's Password Protect Tutorial. This was originally my follow-up tutorial but was never credited, so this one I submitted and has a couple of more comments in the script.
This one will keep you logged in. I havn't tested this, but it is 99% sure to work
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<? //open PHP
ob_start(); //start output buffer, allow cookies
$user = "USERNAME"; //Username to protected page
$pass = "PASSWORD"; //Password to protected page
if(!$_POST['login'] or !isset($_COOKIE[username]) or !isset($_COOKIE[password])) //If you didn't log in it will show the login form, or is also ||
{
echo ('<form method="POST">
<table>
<tr><td>Username:</td><tr><input type="text" name="username="></td></tr>
<tr><td>Password:</td><tr><input type="password" name="password"></td></tr>
<tr><td><input type="submit" name="login" value="Log In"></td></tr>
</table>
</form>');
}
if($_POST['username'] == $user && $_POST['password'] == $pass || $_COOKIE[username] == $user && $_COOKIE[password] == $pass) //If you logged in with the correct username and password, also checks for the cookie, and adds a cookie when form is submitted
{
setcookie("username", $_POST['username'],time()+(60*60*24*5), "/", ""); //set the username cookie
setcookie("password", $_POST['password'],time()+(60*60*24*5), "/", ""); //set the password cookie
?>
HIDDEN CONTENT HERE
<?
}
else //Or if you entered an incorrect username or password
{
echo ('Incorrect username/password!');
}
?>
Enjoy! feel free to post bugs/questions/comments