[英]header(“Cache-Control:max-age = 36000”) Is not working in PHP
I want to cache html page in my browser , and i am tying it on localhost , And I am sending the correct header( using the PHP) in response header but still browser is not caching the response, and every time i request same resource, It connect to server and get response from there 我想在浏览器中缓存html页面,并在localhost上绑定它,然后在响应标头中发送正确的标头(使用PHP),但浏览器仍不缓存响应,并且每次我请求相同的资源时,它连接到服务器并从那里获得响应
At top of my html page I am using 在我的html页面顶部
<?php
header("Cache-Control:max-age=36000");
?>
And the Response
headers are Response
头是
HTTP/1.1 200 OK
HTTP / 1.1 200 OK
Date: Tue, 15 Nov 2016 14:45:37 GMT
日期:2016年11月15日,星期二14:45:37 GMT
Server: Apache/2.4.16 (Win32) OpenSSL/1.0.1p PHP/5.6.12
伺服器:Apache / 2.4.16(Win32)OpenSSL / 1.0.1p PHP / 5.6.12
X-Powered-By: PHP/5.6.12
X-Powered-By:PHP / 5.6.12
Cache-Control: max-age=36000
快取控制:max-age = 36000
Accept-Ranges: none
接受范围:无
Vary: Accept-Encoding
有所不同:接受编码
Content-Encoding: gzip
内容编码:gzip
Content-Length: 154
内容长度:154
Keep-Alive: timeout=3, max=100
保持活动:超时= 3,最大= 100
Connection: Keep-Alive
连接:保持活动
Content-Type: text/html;
内容类型:text / html; charset=UTF-8
字符集= UTF-8
When i saw Cache-Control:max-age=36000
in headers , I was expecting browser will cache this response for 36000 seconds and if i reload page ,I will get the cached response (and different response header) , but i am getting same header after reload ,and getting response straight from server again ,, 当我在标头中看到
Cache-Control:max-age=36000
时,我期望浏览器将该响应缓存36000秒,如果我重新加载页面,我将获得缓存的响应(和不同的响应标头),但是我得到的却是相同的重新加载后的标头,然后再次直接从服务器获取响应,
after reload request headers
are 重新加载
request headers
后
GET /check.php HTTP/1.1
Host: localhost
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-US,en;q=0.8
Should i send any other response header for tell browser to cache the response ? 我是否应该发送其他响应头来告知浏览器缓存响应?
PHP (of course) adds some magical cache-control headers by itself. PHP(当然)本身会添加一些神奇的缓存控制标头。 It is not possible to simply overwrite those with header(), and you have to use session_cache_limiter() to set different cache control headers, or session_cache_limiter('') to disable those magical headers all together..
不可能简单地用header()覆盖它们,而必须使用session_cache_limiter()设置不同的缓存控制标头,或使用session_cache_limiter('')禁用所有这些魔术标头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.