PHP uses header to set browser cache
The function of the header() function is to send a raw HTTP header [Http Header] to the client.
The header is a string sent by the server before transmitting HTML data to the browser using the HTTP protocol. A blank line is required between the header
and the HTML file. Now let me share with you a PHP technology that uses headers to set browser cache.
<?php //定义一个合理缓存时间。合理值屈居于页面本身、访问者的数量和页面的更新频率,此处为3600秒(1小时)。 $cache_time = 60 * 60; $modified_time = @$_SERVER['HTTP_IF_MODIFIED_SINCE']; if( strtotime($modified_time)+$cache_time > time() ){ header("HTTP/1.1 304"); exit; } //发送Last-Modified头标,设置文档的最后的更新日期。 header ("Last-Modified: " .gmdate("D, d M Y H:i:s", time() )." GMT"); //发送Expires头标,设置当前缓存的文档过期时间,GMT格式,我们使用的是GMT+8时区 header ("Expires: " .gmdate("D, d M Y H:i:s", time()+$cache_time )." GMT"); //发送Cache_Control头标,设置xx秒以后文档过时,可以代替Expires,如果同时出现,max-age优先。 header ("Cache-Control: max-age=$cache_time"); echo time(); ?>
About using the header() function. I still have a lot of knowledge points for you. Next, the editor will continue to share with you the usage of the PHP header function and its precautions.
Related recommendations:
Solution to PHP header jump failure, phpheader jump failure_PHP tutorial
##header in PHP Usage summary, PHPheader usage summary_PHP tutorial
PHP Summary of commonly used header header definitions, phpheader header summary
The above is the detailed content of PHP uses header to set browser cache. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











To remove FirefoxSnap in Ubuntu Linux, you can follow these steps: Open a terminal and log in to your Ubuntu system as administrator. Run the following command to uninstall FirefoxSnap: sudosnapremovefirefox You will be prompted for your administrator password. Enter your password and press Enter to confirm. Wait for command execution to complete. Once completed, FirefoxSnap will be completely removed. Note that this will remove versions of Firefox installed via the Snap package manager. If you installed another version of Firefox through other means (such as the APT package manager), you will not be affected. Go through the above steps

[SpringBoot] Passing parameters in the Header through Feign calls How to pass Header parameters through Feign Problem description When we use Feign to request the Api interface of another service in Spring Cloud, there is a need to pass the parameters in the Header. If no special processing is done, it will The parameters in the Header will be lost. Solution 1: Pass it through @RequestHeader(name="headerName"). For example: Feign is defined as follows @FeignClient(name="service-name")pub

The Linux header refers to the beginning of a file or data stream, which is used to contain metadata about the content. By correctly writing and using Header files, developers can better utilize system resources and improve code readability and Maintainability.

How to implement jump in php header: 1. Use "Header("Location:$url");" syntax to implement jump; 2. Use if judgment to implement jump, with jump statements such as "if($_COOKIE[" u_type"]){ header('location:register.php'); } else{ setcookie('u_type','1','86400*360');".

PHP is a powerful programming language that can be used to create dynamic websites and web applications. One of the most powerful features is PHP’s header() method. In this article, we will explore how to use PHP’s header() method to adjust web pages.

Mozilla Firefox can be uninstalled; Firefox is a third-party browser and can be uninstalled if it is not needed. Uninstallation method: 1. In the Start menu, click "Windwos System" - "Control Panel"; 2. In the "Control Panel" interface, click "Programs and Features"; 3. In the new interface, find and double-click Firefox Browser icon; 4. In the uninstall pop-up window, click "Next"; 5. Click "Uninstall".

Differences: 1. The head tag is used to define the head of the document, which is a container for all head elements, and the header tag is used to define the header (introduction information) of the document; 2. All browsers support the head tag, and older versions of browsers None of the browsers support the header tag, and browsers such as IE9+ and above are required to support the header tag.

According to recent news, while Mozilla released the stable version of Firefox 112, it also announced that the next major version, Firefox 113, has entered the Beta channel and supports AV1 animations, enhanced password generator and picture-in-picture features. The main new functions/features of Firefox 113 are as follows: Support for AV1 format animated images (AVIS); Enhance the security of the password generator by introducing special characters; Enhance the picture-in-picture function, support rewind, display video time, and enable full screen more easily Mode provides official DEB installation files for Debian and Ubuntu distributions. Updated bookmark import feature, icons for imported bookmarks are supported by default. Hardware accelerated AV1 video decoding is enabled by default on supported hardware using w
