Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear browser cache memory by php code

I had created a dynamic web page. On the main page there are three sliding images. I created another page to change that main page image (sliding). So after I submit that second page, I wrote a PHP code to go back to main page. But the images are not changing because my browser has that web page in its cache. If I remove cache manually, or restart the browser it is working. How I remove my browser cache in PHP coding? give me a solution. Thanks.

like image 926
sugeesh Avatar asked Jul 21 '26 16:07

sugeesh


2 Answers

You may also add a random string to the image-URI:

<img src="myimage.png?r=12345" alt="">

If the random string varies every time the main page is reloaded (!), the browser will retrieve the image from the server.

like image 58
BurninLeo Avatar answered Jul 24 '26 06:07

BurninLeo


There is one trick that can be used.The trick is to append a parameter/string to the file name in the script tag and change it when you file changes.

<script src="myfile.js?version=1.0.0"></script>

The browser interprets the whole string as the file path even though what comes after the "?" are parameters. So wat happens now is that next time when you update your file just change the number in the script tag on your website (Example <script src="myfile.js?version=1.0.1"></script>) and each users browser will see the file has changed and grab a new copy.

like image 34
Joish Avatar answered Jul 24 '26 07:07

Joish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!