How to control caching when PHP submits a form

Source: Internet
Author: User

In the development process, often appear the form error and return the page when the information is all lost, in order to support page bounce, you can use the following two ways to achieve.

1. Use header header to set cache control header Cache-control.

PHP code
    1. Header (' Cache-control:private, Must-revalidate '); Support page Bounce

2. Use the Session_cache_limiter method.

PHP code
    1. Session_cache_limiter (' Private, must-revalidate '); To write before the Session_Start method

Here are the Session_cache_limiter parameters:

The meaning of several parameters in Session_cache_limiter is:
NoCache: Of course it is not cached (for example: the form information is cleared), but public variables can be cached
Private: Proprietary caching (for example: form information is retained but valid for the lifetime)
Private_no_cache: Private mode but not expired (form information is retained)
Publice: Public Way, (form information is also retained)

Set cache Expiration Time: Session_cache_expire function setting, default is 180 minutes.

Often encounter problems:

1. Session_cache_limiter ("private"); The form information is retained, but if I modify the information that has been submitted, the information presented by the form page or the information in the cache is not automatically refreshed in time, if not session_cache_limiter ( "Private"), and cannot keep form information

Solution:

Add in front of Session_Start

Session_cache_limiter ( "Private, Must-revalidate " ), you can

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.