How can PHP be used to prevent caching in browsers and web servers?
To prevent caching in browsers and web servers, you can use PHP to send headers that instruct the browser not to cache the content. This can be achieved by setting the "Cache-Control" and "Expires" headers to specific values that prevent caching.
<?php
// Prevent caching in browsers and web servers
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 can PHP scripts be optimized to handle heavy load queries without causing database connection issues?
- What are the common mistakes made by beginners when mixing PHP and JavaScript code, and how can they be avoided for better functionality?
- What are the best practices for naming files and folders in PHP projects to avoid errors and confusion?