Hi Marsh,
What I gave you was a set of commands that can help you to evaluate whether a session is present, and an example to see whether the person is logged in. Not a ful working user-namagement system.
As I do not know how you store whether or not a user is logged in, it is impossible for me to give you a working solution. This is also true for the question 'where do I put this code'. You need to decide that. The login script (ll the way to the question "Is the user logged in", you should save as a separate file, e.g., with your settings.inc, and include it on every page. The rest of the script snippet you can use on each page, to determine which action to take.
I'll explain the script a little for you, to get you going:
// Let us start a session:
session_start();
// Lets see whether a variable called authorisation was passed
// in the session from the previous page.
// We require a value of one of that variable for it to be valid
if((array_key_exists('authorisation', $_SESSION)) && ($_SESSION['authorisatie']==1))
{
// Nice, the variable was set with the right value: The user must be logged in.
$loggedin = 1;
// Some more info (e.g., the user ID) is stored in he user_extra variable in the session.
$this_user = $_SESSION['user_extra'];
// Now set a variable with the link to logout:
$loglink = "<a href=\"".$_SERVER['SCRIPT_NAME']."?logout=1\"><img src=\"image.png\"></a>";
}
else
{
// OK, the authorisation was not set, or not equal to one: The person is not logged in.
$loggedin = 0 ;
// Create a link for the menu, to a login system
$loglink = "<a href=\"".$_SERVER['SCRIPT_NAME']."?login=1\"><img src=\"image.png\"></a>";
}
// Did the user ask to be logged out?
if(isset($_GET['logout']))
{
// Then destroy the session, and set loggedin to 0.
session_destroy();
$loggedin=0;
// Do not forget to modify the link to a login system
$loglink = "<a href=\"".$_SERVER['SCRIPT_NAME']."?login=1\"><img src=\"image.png\"></a>";
}
// Did the user ask to login?
if(isset($_GET['login']))
{
// Include your login script
include("Login details");
}
// Is the user loggen in?
if(loggedin)
{
// do stuff
}
else // no he was not
{
do other stuff
}