This article mainly describes how to retain the information that has been filled in after PHP fails to submit a form. For more information, see this article, the most common method is to use the cache method. if the network speed is slow, it may cause problems. The best way is to use ajax.
1. use the header to set the Cache control header Cache-control.
The PHP code is as follows:
Header ('cache-control: private, must-revalidate'); // supports page jump back
2. use the session_cache_limiter method.
The PHP code is as follows:
Session_cache_limiter ('private, must-revalidate'); // before session_start
The following describes the parameters of session_cache_limiter:
The meanings of several parameters in session_cache_limiter are as follows:
Nocache: of course, it is not cached (for example, the form information is cleared), but public variables can be cached.
Private: private cache (for example, the form information is retained but valid during the lifetime)
Private_no_cache: Private mode but not expired (form information is retained)
Publice: public (the form information is also retained)
Set the cache Expiration Time: Set the session_cache_expire function. the default value is 180 minutes.
Frequently encountered problems:
1. session_cache_limiter ("private"); the form information is retained. However, if I modify the submitted information, the information displayed on the form page is still in the cache and cannot be automatically refreshed in time, if session_cache_limiter ("private") is not used, the form information cannot be retained.
Solution:
Before session_start, add
session_cache_limiter( "private, must-revalidate" );
You can.
2. Another method is to use ajax for instances.
The content of the index.html template file is as follows:
JQuery Ajax instance demo