Home >Backend Development >PHP Problem >How to use header() in php to disable caching
How to use header() to disable caching in php: 1. Use header() to set the expiration time; 2. Use header() to set the last updated date of the page to today, which can force the browser to obtain the latest information; 3. , use header() to tell the client browser not to use caching.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php prohibits the browser from using cached pages
This can be achieved by sending a specific cache control original HTTP header through PHP's header() function. The specific code is as follows:
<?php //设置此页面的过期时间(用格林威治时间表示),只要是已经过去的日期即可。 header("Expires: Mon, 26 Jul 1970 05:00:00 GMT"); //设置此页面的最后更新日期(用格林威治时间表示)为当天,可以强制浏览器获取最新资料 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //告诉客户端浏览器不使用缓存,HTTP 1.1 协议 header("Cache-Control: no-cache, must-revalidate"); //告诉客户端浏览器不使用缓存,兼容HTTP 1.0 协议 header("Pragma: no-cache"); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to use header() in php to disable caching. For more information, please follow other related articles on the PHP Chinese website!