I have this at the top of pages that I don't want people accessing unless they're logged in:
<?php
session_start();
if(!isset($_SESSION['Register'])){
if(!isset($_SESSION['Login'])){
header("location:../notLoggedIn.php");
}
}
$get_id = $_SESSION['Register'];
$get_id = $_SESSION['Login'];
?>
This gets a session variable from the code that adds a new user to the database when a new user registers. It also checks if a session has been set from a user logging in rather than registering. Hence one check for register and one for login.
Then, I'm using the session variable as a regular variable so I can access that data on any other pages I might write for the website. So I can have the users id easily available to me.
This works fine when a user registers but not when a user logs in. So, when a user registers the id they are given in the database is available to me to use as it's set in this code that's at the top of every page which puts their id number into the variable $get_id.
The problem is that this variable is already being used but I want it to contain the users id when the user logs in as well. Is there a way to set the variable to check for either of one session variables?