Is checking the referer header a reliable method in PHP to prevent a page from being loaded from the cache?
Checking the referer header in PHP is not a reliable method to prevent a page from being loaded from the cache as the referer header can be easily manipulated or spoofed. A more reliable method is to set appropriate cache control headers in the response to instruct browsers and proxies not to cache the page.
// Set cache control headers to prevent caching
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
Keywords
Related Questions
- What potential issues may arise when including external scripts that use the same variables as the main script in PHP?
- What resources or documentation should be consulted for accurate information on PHP functions like print_r()?
- Why is it recommended to avoid using deprecated properties like 'border' and 'width' in HTML tables and use CSS instead?