Hi Guys,
Just can't find the solution I am looking for. Searched High and Low, nobody hits quite the note I need.
I'm using sessions to carry a login over to subsequent pages, so on those pages obviously I want to check that status. I've tried several ways including:
if (!isset($_SESSION))
Please Login
else
Show Page
//this gives me the page, no matter what the session is set on
and
if ($_SESSION) != ['admin']))
Please Login
else
Show Page
//this gives me Parse error: Undefined Index: 'admin' - but works FINE if I have recently logged in as admin - ie: have a valid session.
At least I understand why this error occurs - Once the session expires, there is no variable called 'admin' stored in a session, it's gone.
Which is what I'm trying to work around. I need to check if the session variable exists AND what it is set to. So if a 'user' stumbles across an 'admin' page, they can't view it.
I want expiring sessions because there will be multiple users and admin using the same machine.
Hence my session timeout is set rather low. I think 15 minutes. I have a logout page which destroys both sessions and cookies, but the timeout is a backup in case someone doesn't logout.
Code:
<?php
session_start();
// Connects to your Database
mysql_connect("localhost", "LOGIN", "PASSWORD") or die(mysql_error());
mysql_select_db("THIS_DB") or die(mysql_error());
if (!isset($_SESSION))
// or if ($_SESSION) != ["admin"]))
{
echo "<p align='center'><font face='Tahoma' size='6'>You are not Admin. Please <a href='index.php'>Login</a></font></p>";
die();
}
else
// Show them this page
echo "BLAH"
?>
Thanks in advance. And sorry if this is a noob question :s