I am including the same files multiple times on the same page. I noticed when I do this, it seems PHP is caching the files. When I generate a random number with the rand function, it is the same in both includes. Anyone know how I can stop PHP from doing this? I tried some different header functions like this but they don’t work:
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // HTTP/1.0
Edit: Ok, I’m dumb and I forgot that I was calling the includes from a jquery script which I believe is caching the files. I went back to see the code some one was asking for and noticed it. Thanks everyone.
I would suggest that including the same file multiple times is not particularly good practice.
A better solution would be to include it once, and call the functions it contains multiple times.
Obviously, this will mean changing the way the code works — I guess it’s currently written as a block of code that is run as soon as it it included. You’d need to change it so that it’s enclosed in a function (or several functions, as required) so that it can be called at will.
Then just include it once at the start of your program.
I know this doesn’t directly answer the question, but doing it this way is better coding practice, and will make your code much easier to manage and maintain.
Hope that helps.