So there's this problem I'm facing all the time using sessions. I was trying to describe my exact problem, but then I've realized that it can be asked so much easier with a much simpler code.
Is there a way, to generate a random number with PHP on each page load?
I can place a simple line like echo rand(1,100); but it won't generate a random number only if I force reload the page CTRL+SHIFT+R
Now, what I have realized, is that if 10-15 seconds pass and I reload the page normally (F5), it does give me a new random number, but if I keep pressing F5, the number never changes
This is my main problem actually. I did a simple login page for a project of mine, and once the session is set and the home page is reloaded, the session is not seen or recognized, only if I force reload the page..
To explain this a bit further. I have created a file with the following content:
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Pragma: no-cache"); // HTTP/1.0
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
echo rand(1,100);
And still, the number won't regenerate for the first 15 seconds, only if I force reload the page with CTRL+SHIFT+R.
Solved
So, after looking into this further more, testing a few things here and there, I just contacted my host to look into this. The reason was Varnish Cache. After we disabled it, everything works as expected. Thanks everyone for the suggestions and comments.