Easiest way to password protect area of a website

Soldato
Joined
11 Jul 2004
Posts
16,151
Location
Neptune
Really has to be very simple. Clicking to go to a particular area which prompts for a username and password. Just one (i.e. not multiple user accounts). Just somewhere where only those that are given the account details can log in.

Thanks
 
Have a link to a page with a form.

Make that form have 2 fields, username and password.

make the action of the form the page which you wish to secure.

then on the secured page...

if ($_POST['password'] == 'foo' && $_POST['username'] == 'bah') {
echo "Secret message";
} else {
echo "Incorrect username or password. Try again sucker!! Click here";
}

That does 1 page.

If you want to do multiple, as suggested above do this but for sessions. so

session_start();
$_SESSION['username_check'] = 'username';
$_SESSION['password_check'] = 'password';

on the pages necessary, then a form to set them.

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

then

if ($_SESSION['username_check'] == $_SESSION['username'] && $_SESSION['password_check'] == $_SESSION[password'])
{
echo 'blah';
}
else
{
echo 'You flail!';
}


example

http://www.poochmedia.com/client_login_demo/
 
Last edited:
Is it me or is that script not grabbing the post variables?

You could try changing anywhere it says $username and $password to $_POST["username"] and $_POST["password"]
 
Back
Top Bottom