How do I deactivate caching in browsers?

百般思念 提交于 2019-12-31 03:17:07

问题


For instance, if you exit your Yahoo mail and then click the back button, it will not load the last page, it will redirect you to the login page.

I have to do this with my PHP code, I'm using CodeIgniter.

Some friends told me to disable caching but that will be a bad thing because I have a lot of images in my system and it would be bad to download them every time.

How do I do this with PHP?


回答1:


Disable caching of your page with the following code :

http://php.net/manual/en/function.header.php

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>



回答2:


Try these:

<?php
header("Expires: Fri, 01 Jan 2010 05:00:00 GMT");
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
header( 'Cache-Control: post-check=0, pre-check=0', false );
header( 'Pragma: no-cache' ); 
?>



回答3:


The simple answer to avoid caching on the client browsers is to configure the Cache-Control HTTP response header.

http://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Avoiding_caching

However, I don't have a PHP snippet with me to show you how to do it exactly. It should as simple getting the HTTP response object, and setting a header "Cache-Control" with value "no-store, must-revalidate"



来源:https://stackoverflow.com/questions/6017231/how-do-i-deactivate-caching-in-browsers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!