php password protection script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

theres plenty of tutroials on how to use databses such as mysql. google will return more results than you could read in a year probably lol. theres prob some good ones on this board as well.


but you dont really need a db to have more than 1 user, heres a sample:


Code: Select all

<?php


$users = array( // add as many as you want
    'username1' => 'password1',
    'username2' => 'password2',
    'username3' => 'password3',
);



$username = $_POST['username'];
$password = $_POST['password'];


$valid_user = false;

foreach ($users as $uname => $upass) {
    if (($username === $uname) && ($password === $upass)) {
        $valid_user = true;
        break;
    }
}



if ($valid_user) {
    echo 'valid';
} else {
    echo 'go away';
}






?>
attackle98
Forum Newbie
Posts: 11
Joined: Wed Oct 27, 2004 10:13 am

Post by attackle98 »

so i just need to add lines 11,12,13 to the code for it to work or did you add something else that i need to add to the code?
attackle98
Forum Newbie
Posts: 11
Joined: Wed Oct 27, 2004 10:13 am

Post by attackle98 »

ok........
Post Reply