How can PHP be used to prevent a page from being loaded from the cache when the user navigates back using the browser's back button?
When a user navigates back using the browser's back button, the browser may load the previous page from the cache instead of requesting it from the server again. To prevent this, you can use PHP to send headers that disable caching for the page.
<?php
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.
?>
Keywords
Related Questions
- How does PHP handle comparisons between boolean values and integers in conditional statements?
- What are the potential issues when using the header() function for redirection in PHP?
- How can PHP developers ensure fairness in distributing instant prizes throughout the day in a contest with a limited number of daily winners?