This article describes how the PHP submission form failed to retain the information to fill out some of the methods summarized, the most common is the use of caching, this method if the slow speed of the network may be a problem, the best way is to use Ajax.
1. Use header header to set cache control header Cache-control.
The PHP code is as follows:
Header (' Cache-control:private, Must-revalidate '); Support page Bounce
2. Use the Session_cache_limiter method.
The PHP code is as follows:
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 already 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"); Cannot keep form information
Solution:
Add in front of Session_Start
Session_cache_limiter ("Private, must-revalidate");
Can.
2. Another way we can use Ajax to instantiate
The index.html template file is roughly as follows:
The contents of the login.php file are as follows:
<?php
Echo json_encode (Array (' username ' =>$_request[' username '), ' password ' =>$_request[' password ')) ;
? >
In this way, we do not need to refresh the page, if the failure will be submitted directly, so you can save the 100% commit failure after the data is not lost.