Solution to the disappearance of returned content after a form submission error (PHP website), php_PHP form tutorial

Source: Internet
Author: User
Tags php form
Solution to the problem of content disappearance returned after the form is submitted incorrectly (PHP website), form php. Solution to the problem of content disappears after the form is submitted incorrectly (PHP website). What should I do if the returned content disappears after the form php form is submitted incorrectly, today, let's analyze and solve this problem. The solution (PHP website) to the problem that the returned content disappears after the form is submitted incorrectly, and the form php

What if the returned content disappears after the form is submitted incorrectly? let's analyze and solve this problem today.

Overview:

When submitting the form information, a problem occurs: After the user fills in and submits the form, the program determines that it does not meet the requirements and returns the result, the returned information is cleared. It doesn't matter if you fill in less information. if you fill in more information, this will directly hit the good mood of the person who fills in the information. Therefore, solving the problem that the content filled in after an error is returned after the form is submitted is an urgent issue to improve user experience.
For this problem, we have summarized the following situations:
(1) the session_start function is used on the page. this function forces the current page not to be refreshed. the solution is to add the following code after the function:

Header ("Cache-control: private"); // note that your PHP program cannot have any output before this line.

You can also add the following solutions before session_start:

Session_cache_limiter ('nocache'); // clear the form session_cache_limiter ('private'); // do not empty the form, only session_cache_limiter ('public') during the session takes effect '); // do not empty the form, as if no session is used

The preceding session settings will cause the seesion to be cached. as a result, when you apply the session, the session information cannot be updated. For this reason, this article provides the following solutions.
(2) use the Header method to set the message Header Cache-control and add the following code to the page:
Header ('cache-control: private, must-revalidate'); // page jump is supported. Note that no output is available before this line.
(3) use the session_cache_limiter method and add the following code to the page:
Session_cache_limiter ('private, must-revalidate'); // note that it should be written before the session_start method.
The following describes the Cache-Control Message header fields:
Cache-Control specifies the Cache mechanism that requests and responses follow. Setting Cache-Control in a request message or response message does not modify the Cache processing process of another message.Cache command during requestIncluding no-cache, no-store, max-age, max-stale, min-fresh, only-if-cached, commands in the response message include public, private, no-cache, no-store, no-transform, must-revalidate, proxy-revalidate, and max-age. The instructions in each message are as follows:

Public:Indicates that the response can be cached in any cache area.

Private:Indicates that the whole or part of the response message of a single user cannot be processed by the shared cache. This allows the server to only describe part of the user's response message, which is invalid for requests of other users.

No-cache:Indicates that the request or response message cannot be cached.

No-store:Used to prevent unintentional release of important information. Sending a request message does not cache the request and response messages.

Max-age:Indicates that the client can receive responses with a lifetime not greater than the specified time (in seconds.

Min-fresh:Indicates that the client can receive a response whose response time is earlier than the current time plus the specified time.

Max-stale:Indicates that the client can receive response messages beyond the timeout period. If the value of the max-stale message is specified, the client can receive response messages that exceed the timeout period.

After reading this article, you can thoroughly solve similar problems. I am particularly reminded that this solution is only applicable to php websites. remember it.

What should I do if the returned content disappears after the PHP form is submitted incorrectly on the php website? I will analyze and solve this problem today...

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.