QUOTE(morcomm @ 26 May, 2008 - 01:04 AM)

Hi,
I used this tutorial to create a login page
http://www.13dots.com/forum/index.php?showtopic=16156, but have a few questions.
When I navigate to a page in the folder that is not the login page, I still can view it. I don't want this, but would prefer the page to re-direct me to the login page if I have not yet entered my details.
I think that I might be going wrong with this bit of code from the tutorial:
CODE
<?php
include("config.php");
$cookuser = $_COOKIE["cookuser"];
$cookpass = $_COOKIE["cookpass"];
$adminpass = md5($adminpass);
if($cookuser && $cookpass) {
if(($cookuser == $adminuser) && ($cookpass == $adminpass)){
echo("You have succesfully logged in! Please feel free to browse this secure admin page! To loggout go to <a href=logout.php>logout.php</a>");
//Any protected stuff you want goes in here!
}
else{
echo($incorrect_error_message);
}
}
else{
echo($not_logged_in_message_error_message);
}
?>
It is more than likely the place that says //Any protected stuff you want goes in here! that I am not understanding.
If anyone thinks this is not a good script to use and that there could be a better one, please let me know. I need to password protect a backend to a news system.
An easy way to do this is, when one is logged in, a variable (
$_COOKIE['loggedin'] ) is set to true, and when one isn't, the variable is set to false.
Then at the top of every page someone needs to be logged in to view, just preform a if statement check (before ANY other output is made, including <!DOCTYPE> and <HTML>).
CODE
if ( !($_COOKIE['loggedin']) )
{
header (Location: "/login.php");
}