Home  >  Article  >  php教程  >  PHP提交表单后如何控制缓存

PHP提交表单后如何控制缓存

WBOY
WBOYOriginal
2016-06-21 08:50:57721browse

 

在开发过程中,经常会出现表单出错而返回页面的时候填写的信息全部丢失的情况,为了支持页面回跳,可以通过以下两种方法实现。

 

1.使用header头设置缓存控制头Cache-control。

PHP代码

  1. header('Cache-control: private, must-revalidate');  //支持页面回跳     

2.使用session_cache_limiter方法。

PHP代码

  1. session_cache_limiter('private, must-revalidate'); //要写在session_start方法之前    

下面介绍一下session_cache_limiter参数:

session_cache_limiter内的几个参数意义是:
nocache:当然是不缓存(比如:表单信息被清除),但公共变量可以缓存
private:私有方式缓存(比如:表单信息被保留,但在生存期内有效)
private_no_cache:私有方式但不过期(表单信息被保留)
publice:公有方式,(表单信息也被保留)

设置缓存过期时间:session_cache_expire函数设置,缺省是180分钟。

常遇见问题:

1。session_cache_limiter("private");表单信息是保留了,但是如果我修改已经提交的信息,表单页面所呈现的信息还是缓存里信息,没能及时自动刷新,如果不用session_cache_limiter("private");又不能保留表单信息

解决方案:

在session_start前面加上

session_cache_limiter( "private, must-revalidate" );便可



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn