Table of Contents
php prohibits browsers from using cached pages, php prohibits caching of pages
How to return to the original page when php prohibits the browser from using cached pages
How to prevent the browser from "back" and then "forward" in a PHP page to return to this page and use cache
Home Backend Development PHP Tutorial PHP prohibits the browser from using cached pages, PHP prohibits caching pages_PHP tutorial

PHP prohibits the browser from using cached pages, PHP prohibits caching pages_PHP tutorial

Jul 13, 2016 am 10:14 AM
php Browser cache

php prohibits browsers from using cached pages, php prohibits caching of pages

The example in this article describes how to prevent the browser from using cached pages in PHP. Share it with everyone for your reference. The specific method is as follows:

Page caching is sometimes not needed. We can prevent the browser from caching the page.

In PHP, you can easily use the following statement to disable page caching, but it is difficult to remember and organize it for everyone’s convenience.
The php code is as follows:

Copy code The code is as follows:
//Set the expiration time of this page (expressed in Greenwich Mean Time), as long as it is a date that has passed.
header ( " Expires: Mon, 26 Jul 1970 05:00:00 GMT " );
//Set the last updated date of this page (expressed in Greenwich Mean Time) to the current day to force the browser to obtain the latest information
header ( " Last-Modified: " . gmdate ( " D, d M Y H:i:s " ). "GMT " );

// Tell the client browser not to use cache, HTTP 1.1 protocol
header ( " Cache-Control: no-cache, must-revalidate " );

// Tell the client browser not to use cache and be compatible with HTTP 1.0 protocol
header ( " Pragma: no-cache " );
?>

This is useful for certain pages, such as order information and products under the order, and clearing the corresponding product data in the shopping cart.
You definitely don’t want the user to reach the last page, have already generated an order, and then click the browser’s return button to return to the previous page.
Then add it on the order address page:
Copy code The code is as follows:
header("Cache-Control:no-cache,must-revalidate,no-store"); //This After no-store is added, it will be valid under Firefox
header("Pragma:no-cache");
header("Expires:-1");

This page is no longer cached, and there is a page that jumps to the empty shopping cart if the items in the shopping cart are empty. Then the user clicks the browser to go back, and when he comes back, he goes directly to the shopping cart page.

I hope this article will be helpful to everyone’s PHP programming design.

How to return to the original page when php prohibits the browser from using cached pages

As long as the server-side design is rigorous, there is no point in doing it on the client-side.
The page expiration is the set http header. If you want to modify the header, you have to intercept the http data communication packet. After the modification is completed, it is not easy to restore the http conversation.
And the designer usually sets a certain mark to indicate that the test is over after submission. Even if you can submit again, there will definitely be errors. Of course, it does not rule out that the designer is a stupid person. Condition.

How to prevent the browser from "back" and then "forward" in a PHP page to return to this page and use cache

Add these three lines of code to the page and see if it works:
header("Expires: -1");
header("Cache-Control: no_cache");
header("Pragma: no -cache");

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/907833.htmlTechArticleHow to prohibit browsers from using cached pages in php, php prohibits caching of pages. This article tells an example of php prohibiting browsers from using caches. page method. Share it with everyone for your reference. Specific methods...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Apr 18, 2025 am 09:24 AM

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

What is the reason why the browser does not respond after the WebSocket server returns 401? How to solve it? What is the reason why the browser does not respond after the WebSocket server returns 401? How to solve it? Apr 19, 2025 pm 02:21 PM

The browser's unresponsive method after the WebSocket server returns 401. When using Netty to develop a WebSocket server, you often encounter the need to verify the token. �...

Why can't JavaScript directly obtain hardware information on the user's computer? Why can't JavaScript directly obtain hardware information on the user's computer? Apr 19, 2025 pm 08:15 PM

Discussion on the reasons why JavaScript cannot obtain user computer hardware information In daily programming, many developers will be curious about why JavaScript cannot be directly obtained...

See all articles