Forgot Password / Register
Site Statistics
Total Members: 509
Total Tutorials: 242
Newsest User: Lestop
Todays Unique Hits: 204
1 Users 2 Guests Online

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
chrism
Author:
Views:
1166
Rating:
Posted on Wednesday 7th March 2007 at 08:51 PM
ShadowMage
ShadowMage
i did one with sessions lol
Posted on Wednesday 7th March 2007 at 08:48 PM
MOD-Dan
MOD-Dan
Also this would work with the techtuts user system we are using sessions here not cookies! Recoding needed!
Posted on Wednesday 7th March 2007 at 08:09 PM
ShadowMage
ShadowMage
its echoing the bottom line anyway when i look at it o.o i'll post a simple session one here in a bit =P
Posted on Wednesday 7th March 2007 at 07:58 PM
paradox
paradox
no becuase theres nothing connection to the database and it uses its own cookie
Posted on Wednesday 7th March 2007 at 04:30 PM
ashwill
ashwill
Dont you need to include config?
Posted on Wednesday 7th March 2007 at 05:59 AM
FtH8er
FtH8er
Well mine comes up on the page but doesnt go anywhere lol. When i say this i mean, when i enter the info into the boxes, and login, it acts like it is gonna process it, but then it just reloads the page. Plz Help. Thx