I am trying to create a website and teach myself at the same time. I have implemented a database connection to allow users to register and sign in/out of the website but for some reason the session variables don't appear to be accessible from one specific page.
I have got the following php code on 2 pages that are in the same directory but the session vars are only accessible from one of the pages? Can anyone suggest what might be causing this and how this can be resolved?
<?php
// Initialize the session
session_start();
if(isset($_SESSION['username'])){echo "A";}
echo $_SESSION['username'];
?>
The initialisation of the username is done here:
if (password_verify($password, $row["password"])) {
session_start();
$_SESSION['username'] = $username;
$_SESSION['userType'] = $row["userType"];
header("location: ../index.php");
}