I'm trying to use the PHP $_SESSION in my code. Below is the code but the problem is that PHP $_SESSION is not working globally.
<?php
session_start();
require_once("config.php");
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
$_SESSION["log_user"];
?>
Here I have declared the $_SESSION before the code then I try to use it in the body below is the code.
<?php
$log_user=$_SESSION['log_user'];
$getlogged = "SELECT * FROM user_accounts WHERE userid='$log_user'";
$getlogged=mysqli_query($db, $getlogged);
while ($getlogged_row = mysqli_fetch_array($getlogged)) {
?>
<div> Name : <?PHP echo $getlogged_row['name']; ?> </div>
<div> Name : <?PHP echo $getlogged_row['userid']; ?> </div>
<?php } ?>