


Use PHP to disable the cache problem of IE and Firefox_PHP tutorial
After searching for many ways to improve the network speed, I finally solved it
In fact, the simplest way is to add the tag in the header
You can also use program control
header("Cache-control:no-cache,no-store,must-revalidate");
header("Pragma:no-cache");
header("Expires:0");
?>
If in or header("Cache-control:no-cache,no-store, must- revalidate"); without no-store, Firefox's cache cannot be solved
The following is a specific analysis for you:
Two caches of Firefox and IE browsers Important differences
After you create a WEB service, there are usually two types of cache that need to be configured:
Set the html resource to expire immediately when the website is updated, so that users who are browsing can quickly Get updated.
Set all other resources (such as images, CSS, javascript scripts) to expire after a certain period of time.
This caching solution covers some of the ideas mentioned in the Two Simple Rules for HTTP Caching article on how to handle updates.
Now that HttpWatch 6.0 supports Firefox, we would like to discuss how Firefox handles cache differently from IE. The method of setting a longer expiration time (the second item above) can still be used directly in Firefox, but configuration 1 is There are still subtle differences between the two.
In the previous article, we divided the first one into:
Sometimes dynamic HTML pages need to be updated from the server immediately to be displayed at any time - even using back button. For example, displaying the status of a bank account or an online order.
Static HTML pages, such as contact, FAQs or sitemaps, if they set the Last-Modified response header, allow the browser to reload when needed Verification, you can take advantage of the cache.
The rest of this article discusses two important differences that affect HTML page caching in Firefox.
1. Use no-cache to prevent Firefox cache invalidation
You can simply set the following response header to prevent IE from caching anything:
Cache-Control: no-cache
Pages using this response header will not be saved in the cache, and IE will always will be reloaded from the server; even if you use the back button. The following example uses HttpWatch to monitor an online store. When we click the back button after submitting the order form, the result is as follows:

However, this response The header cannot prevent Firefox from caching. This means that under normal access conditions, Firefox will always use the cached page until it sends a GET request to recheck. And if the page is accessed through the back button, Firefox will not access it again. server, but simply loads directly from the cache.
So how can you turn off the cache in Firefox? The answer is simple, it cannot be turned off. Because Firefox relies on the copy in the cache as "File-> Save As ", "View Source" operations. However, you can control where the page is cached and which cache entries can be used for display.
The following response headers prevent persistent caching in Firefox, forcing the page to be cached into memory:
Cache-Control:no-store
This header can also prevent the cached page from being accessed when using the back button, which will trigger an HTTP GET request.
The combination of the values of these two response headers You can get the expected results in IE and Firefox by using:
Cache-Control: no-cache, no-store
As shown in the following HttpWatch response header tag:

2. If you do not set an expiration time, Firefox will set one for you. When IE encounters an http response without an Expires header, it thinks that the cache entry can never be automatically used until it is re-validated from the service. Due to IE's A setting item of the temporary file "Check for a newer version of the web page" defaults to "Auto", so it is usually done once per session.
This provides a reasonable way to control the caching of static HTML content. The user's newly opened IE will get the latest version of the html, and the cached version will be used until I close IE.
Firefox handles missing Expires headers differently. If there is a Last-Modified header in the impact, it will use it A tentative expiration value specified in the HTTP 1.1 specification RFC2616:
(quoting specification :)
And, if there is a Last-Modified time value in the response, the tentative expiration value cannot exceed a ratio of the time interval from this value to the present. Generally, this ratio is set to 10%.
The calculation method is as follows:
Expiration time = current time + 0.1 * (time difference from Last-Modified to now)
For example, if your static HTML file was last modified 100 days ago, the expiration time is 10 days later. The following example It is an HttpWatch cache tag without an Expires header page:
pic3
Firefox automatically sets the expiration time to 8 days later, because this page has not been modified for about 80 days.
This means that in order to maintain control For your HTML pages, as we discussed in the Two Simple Rules for HTTP Caching article, you'd better set an appropriate Expires value on your WEB server for your static resources such as HTML, images, CSS files, etc.
Conclusion
To ensure consistent caching behavior between IE and Firefox, you should:
Always specify an Expires header. Generally set -1 to use html pages to refresh instantly or Set a specific expiration time for other resources such as images, CSS, and javascript
If you want to force the page to refresh, even when clicking the background button, then set Cache-Control: no-cache, no-store

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











JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.
