I'm using the $_SESSION to store messages to display to the user.
$_SESSION['message']['error']=" an error appear",
$_SESSION['message']['warning']="not good !"
my HTML page is generated by including some HTML views and and generating variables.
This is done between ob_start and ob_get_clean()
Then i'm echoing the result to the user.
After that i unset $_SESSION['message'] to left a clean situation for the next pages.
it seems that the unsetting is parallelised with the ob_start()
When i comment the unset, i've got the right messages displayed. But when I uncomment it the messages are displayed empty.
I've tried to unset the $_SESSION['message'] at different position in my code. I have tried setting it to an empty array.
It seems that the PHP core is doing some optimisation and interpreting my code in an inappropriate order.
It Looks kinda like this:
ob_start();
$ctrl = new $classeControleur();
$ctrl->$action();
$contenu = ob_get_clean();
include CHEMIN_VUE.'header.view.php';
require('aside.php');
echo '<div id="portail_application_centre">';
echo $contenu;
echo '<div>';
// HTML END
unset($_SESSION['message']);
Please remember that sessions in PHP are blocking and only one process can access given session file at a time - any other process trying to access the same session will sit and wait for its turn. Once you open session and it will block forever until you either close it or program finish by itself and exit.
$_SESSION superglobal holds key/value pairs that belong to last open session, but this variable is not session itself. It allows you to modify open session and it remembers data from previously opened session, nothing more.
You have to start session manually (unless configured otherwise in php.ini - don't do it) before you can write to it. What you need to do is to open session, make changes, then close it right away. You can reopen it later if needed.
Always close session as soon as you are done writing to it, so other process can access it and save their changes. If you leave it open no one will be able to save any changes.
Here I made a little example how to access session data couple times during one run of the script.
Let me know if that's any help.