Greetings all,
I am working on a website with data I only want logged in users to see. I currently have it where once they have logged in successfully, they can browse the website, and if they are not, they are directed to the login page. Sounds great. However, if they attempt to view a private page a second time, they apparently have a session that allows them to visit. I want to make it where you must login to have a session. How is this done? Here is my code as it stands right now:
The login page:
<?php
session_start();
$_SESSION['loggedin']='1'
?>
//my html code with a login table
I don't think that is where the problem is, I think its in the subsequent pages, which all open with this code:
<?php
session_start();
if ($_SESSION['loggedin']!=1){
header("Location:main_login.php");
exit;
}
if (isset($_GET['logout']))
{
$_SESSION = array();
if ($_COOKIE[session_name()])
{
setcookie(session_name(), '', time()-42000, '/');
}
session_destroy();
header('Location: main_login.php');
}
?>
//my html code.
Like I said, the first time they try to access the any of these pages it does redirect to the login page, but if they try it a second time, they somehow are allowed in. What am I doing wrong?