I have 2 pages. page1 initiates a session variable and has a link towards page2. Both page include the same header, which has the session_start.
Yet I can't manage to understand why the session array isn't going through the second page.
header.php
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<body>
<?php print_r($_SESSION); ?>
page1.php shows correctly the $_SESSION content as seen below
<?php
include('header.php');
$_SESSION['usager'] = "popo";
?>
<a href="page2.php"> Page 2 </a>
</body>
</html>
page2.php has an empty array as $_SESSION, thus showing nothing
<?php
include('header.php');
echo "hi";
?>
</body>
</html>
What I have tried
- Change the href from a relative to an absolute link. No difference.
- Check PHPSESSID, it's there.
- Some projects on the same server don't trigger that issue.
- On Chrome, do shift + f5 to remove cache. No difference.
Pages I visited
- Very similar problem in PHP Bug website
- $_SESSION is empty after redirecting
- After redirection my $_SESSION is empty, why?
- php session lost after header() redirect
- Php session variables being lost after redirect
- Session lost after page redirect in php
- PHP session variables lost after redirect
- PHP Session variable is empty after redirecting to another page [duplicate]