Sorry for all the questions today, but I don't seem to be getting anywhere.
I have a login script as follows:
$sql = "SELECT * FROM users WHERE user_name='$user' AND password='$pass'";
$user_nickname = $row['user_nickname'];
$result = mysqli_query($con, $sql);
if($row = mysqli_fetch_array($result)) {
$_SESSION['loggedIn'] = true;
$_SESSION['isAdmin'] = ($row['is_admin'])? true : false;
$_SESSION['userNickname'] = $user_nickname;
header('Location: index.php');
}else{
echo 'Incorrect User
}
Then on my index page, I pull files via AJAX into the centre, so for example on the user profile page I have
<h1 class="page-header">Hello, <?php session_start(); echo $_SESSION['userNickname']; ?></h1>
At the start of the page where this code is, I have:
<?php
session_start();
if( ! $_SESSION['loggedIn'] ) {
// not logged in redirect direct to login page
echo "<div id='loadcontent' class='col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main'>";
include "loginscreen.php";
echo "</div>";
die();
}
?>
I have also tried
if (isset($_SESSION["userNickname"])) {
echo $_SESSION["userNickname];
}
Am I missing something? I have been searching around, but I can't seem to understand why it's not being stored.
The code I am expecting is "Hello, NICKNAME"