Q: Why are all fields cleared after I click the back button of the browser?
A: This is because you have used the session_start function on your form submission page. This function forces the current page not to be cached. Solution: After your Session_start function, add
The code is as follows: |
Copy code |
Header ("Cache-control: private "); |
Note that your PHP program cannot have any output before this line.
In addition, the session-based solution is added before session_start.
The code is as follows: |
Copy code |
Session_cache_limiter ('nocache'); // clear the form Session_cache_limiter ('private'); // do not clear the form, only during the effective period of the session Session_cache_limiter ('public'); // do not clear the form, as if the session is not used |
Another method is to use cookies. When a user inputs data, the cookie is saved. If an error occurs, the cookie value is returned.
The commonly used ajax method does not need to be deprecated if it is submitted locally.