I have a page, index.php, which includes another page, session.php. In session.php, I would like a session to start, and to set a session variable.
Upon running index.php, I would like the session variable set in session.php to be displayed.
I expected my code to work, but I have found that it does not.
index.php:
<?php
include "path/to/session.php";
echo $_SESSION['var'];
?>
session.php:
<?php
session_start();
$_SESSION['var'] = "yes";
?>
I expected the output to be yes, and instead return no output.
EDIT:
I have tried this on Firefox and Chrome, to no discernible difference.
Upon inserting error handling as suggested below, it has not printed any errors.
Putting an echo "hi"; on session.php will output hi on index.php, so there's no obvious issue with the include or the pathing.
If I run session.php, having it echo the session_id(), the output will be the same each time I refresh the page; if I have the index.php echo the session_id(), it will not produce an output, and the output sent from session.php will be different each time I refresh the page, and does not appear to be reflective of session.php's session_id() when run from that page.