Are you sure that don't have the msg session value changed at another place in your code ?
Something else : it's not a good idea to store the password in the session ;).
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
setting the session when a user is logged in
<?php
require __DIR__ . "/../dbConnection.php";
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
require __DIR__ . '/../validation/loginValidation.php';
if(empty($errors))
{
$_SESSION['email'] = $emailRow['email'];
$_SESSION['id'] = $emailRow['id'];
$_SESSION['password'] = $emailRow['password'];
$_SESSION['msg'] = "Welcome back!";
header('location:/dashboard.php');
}
}
and displaying it on the the footer page and footer is common to all pages here the code to display it
$s = isset($_SESSION['msg']) ? $_SESSION['msg'] : "";
var_dump($s);
$user_id = isset($_SESSION['id']) ? $_SESSION['id'] : "";
echo $user_id;
die();
error is this string(0) "" 57 where 57 is the session['id'] and string is empty for the msg how can be this happened? anyone help me out :(
Please or to participate in this conversation.