How can PHP be used to prevent pages from loading from the cache after logging out?
After logging out of a website, it is important to prevent pages from loading from the cache to ensure that sensitive information is not accessible to unauthorized users. This can be achieved by adding cache control headers to the PHP code, specifically setting the "Cache-Control" and "Expires" headers to prevent caching.
// Prevent pages from loading from the cache after logging out
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1
header("Pragma: no-cache"); // HTTP 1.0
header("Expires: 0"); // Proxies
Related Questions
- How can error reporting be utilized in PHP scripts to identify and troubleshoot errors effectively?
- What are the advantages and disadvantages of using aggregate functions in PHP for data manipulation?
- What are the best practices for labeling form fields in PHP-generated HTML forms to improve accessibility and usability?