如何在 php/ 中编写未来 8 小时的 HTTP 响应标头
我知道如何在 PHP 中设置基本的过期 HTTP 响应标头,如下所示...
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
但是,我想让它更加动态一点,因为我想使用 PHP,在用户访问时提前八小时指定过期时间内容。有人可以帮助我实现这个目标吗?
提前致谢!
I know how to set a basic expires HTTP response header in PHP as follows...
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
However, I want to make it a little more dynamic in that I want to, using PHP, specify an expiration time eight hours ahead of when the user accesses the content. Could someone help me achieve this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用Cache-Control max-age 相反,表示相对于响应时间的秒数:
示例:
请注意,如果 Expires 和 Cache-Control 的 max-age 都存在,则 max-age > 优于 Expires:
You can use Cache-Control’s max-age instead that indicated the number of second relative to the response time:
An example:
Note that if both Expires and Cache-Control’s max-age are present, max-age is preferred over Expires:
使用 strtotime 制作未来的时间戳,以及 gmdate 将其格式化为 GMT 时区的字符串。
Use strtotime to make a timestamp in the future, and gmdate to format it as a string in the GMT timezone.