search
HomeBackend DevelopmentPHP Tutorial页面缓存 - PHP中如何禁用用户本地浏览器缓存?

题境: 企业内部一些文件,通过flexpaper在线浏览,原本的office文件都转化成了swf格式,而公司这些文件是只允许员工在线浏览,不允许复制、打印与传播的,如果本地缓存(临时)文件夹中包含这个swf文件,就可以直接拿走并传播了(即使不能完全控制住,但如果达到IE临时文件夹中没有随意缓存此文件的话,也能一定程度上达到效果)

我希望用户本地IE临时文件夹不能缓存某页面的内容,查找资料一般都是php中header控制,html中meta控制,然后我也试用了,结果都没达到效果,在IE对应的本地缓存文件夹中还是可以找到该页面的内容,请各位帮忙指点一下,谢谢了

页面缓存 - PHP中如何禁用用户本地浏览器缓存?

页面缓存 - PHP中如何禁用用户本地浏览器缓存?

回复内容:

题境: 企业内部一些文件,通过flexpaper在线浏览,原本的office文件都转化成了swf格式,而公司这些文件是只允许员工在线浏览,不允许复制、打印与传播的,如果本地缓存(临时)文件夹中包含这个swf文件,就可以直接拿走并传播了(即使不能完全控制住,但如果达到IE临时文件夹中没有随意缓存此文件的话,也能一定程度上达到效果)

我希望用户本地IE临时文件夹不能缓存某页面的内容,查找资料一般都是php中header控制,html中meta控制,然后我也试用了,结果都没达到效果,在IE对应的本地缓存文件夹中还是可以找到该页面的内容,请各位帮忙指点一下,谢谢了

页面缓存 - PHP中如何禁用用户本地浏览器缓存?

页面缓存 - PHP中如何禁用用户本地浏览器缓存?

我在 IE 对应的本地缓存文件夹中还是可以找到该页面的内容

在缓存文件夹中找到很正常。

至于你的问题「如何禁用用户本地缓存」,可以把缓存文件夹设置为只读。别笑,我很正经的。

你只看了 header,为什么不看看 Status Code 啊?如果是 304,则表示 Not Modified,说明被缓存了。

如果被缓存了,会不会在本地缓存文件夹中找到呢?答案是可能会。

本地缓存是浏览器的功能,可以不用去管。

禁用缓存的目的是:当你去请求 web server 时,server 总是把最新的文件给出浏览器,而不用检测这个文件是否更新过。当他传回浏览器的时候,浏览器 IE 就把这个文件(或者一部分)放到本地存起来。

虽然这个文件夹被称为「缓存文件夹」,其实他只是是「临时文件夹」。

其它浏览器也许不使用「缓存文件夹」,比如使用一个小型数据库系统,例如 sqlite。

其实,把内存的内容放到硬盘上,是一种传统,也是一种哲学。

操作系统也经常把一些内存放到硬盘里,「微软」管它叫「虚拟内存」。

最后回答作者的问题:如何禁用本地缓存?没必要。

我非要禁用。

  1. 设置为只读
  2. 在 IE 的设置里面应该可以禁用
  3. 修改注册表

按照补充,给出我的看法:

在这种环境下,你需要的肯定是一个需要客户端配合的程序,用来对浏览器的行为进行修改,而不是单纯在服务器端进行开发。

如果简单点考虑,你可以为浏览器开发插件,用来修改和约束浏览器的缓存行为。然后在服务器端上,要求只有安装了你的插件才能提供内容。但这种方法仍然有被HTTP抓包的风险。内贼难防,千万不要认为一定程度的安全就够用了。

我觉得比较好的方案是直接放弃Web应用这个架构,而用客户端软件去替代之。内容格式上,也放弃flash,而只是简单的传输带水印的中低分辨率图像。在网络传输上,引入不对称加密。这样只要服务器的私钥不泄露,可以说固若金汤,任何人都拿不到印刷质量的文件原文。

但这仍然防止不了截屏、录像、拍照,甚至更简单点:人肉记忆等种种原因造成的数据泄露。这些方式我不多解释,就认栽吧。


感谢邀请。的确,正面对抗缓存系统,妄图更改所有用户的浏览器设置,确实是件荒谬的事情。但这件事并非没有变通的方法。

有个细节,就是带有POST数据的HTTP请求,一般而言是不缓存的。RFC 2616的9.5 POST一节,有如下的注释:

Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields. However, the 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource.

其实也很容易理解:POST都是大量数据,浏览器缓存不起,也检索不起。

这样,方法就很简单了:主网页载入一个空框架,提交一个带POST数据的AJAX请求载入实质性的数据就行了。服务器端的那些缓存参数还可以照用。

但注意:这只是在一般情况,使得浏览器并不中长期保留这些内容。并不是说保证浏览器就一定不缓存这些内容,毕竟客户端的行为是你所不能控制的。尤其是为性能起见,在短时间内做的高速缓存,这个只要存在就几乎没有对抗的可能。


不过,更重要的是,我很想知道你如此处心积虑与浏览器本地缓存作对的理由。

数据保密?可是只要面对的是浏览器环境,你的传输和网页内容被截获、复制、分析、污染,只要用户愿意就没什么做不到的。(这个你需要的是一个专用的服务器-客户端结构)

保证时效性?这完全不必非去禁用客户端的本地缓存。

我猜不透你这个问题的目的。所以我建议你补充一下你的应用环境,和你期望的目的供大家参考。而不是认死了一个技术目标不放。

网易云课堂里面那个获取视频文件的链接在firefox中的response headers内容如下:

页面缓存 - PHP中如何禁用用户本地浏览器缓存?

我用IE浏览器播放,在本地缓存(临时)文件夹中没有找到对应的视频文件的,我猜测是应该服务器端做了处理

这个问题的本质需求是在浏览器里面做文档安全,我知道的有几种做法:
1、在IE中使用控件,可以很好的控制office文档的权限,可以先看看NTKO的资料。
2、转换为FALSH的格式,好像控制每次从服务器上获取一页的内容,这样的话大大提高了拿走文件的难度。

说一个相关的非技术问题:

录屏软件!

只要是静态资源,浏览器在加载的过程中,总是会“暂存”。或者换句话说,我通过firebug,或者查看源代码,都可以拿到你的路径,直接下载就完了。你想的控制浏览器缓存的思路也许该换换。

@adam 的说法可能是通行的做法。类似的,在线的文档阅读器,Flash的角色是一个播放器/阅读器,同时为了安全考虑,Flash中内置了加解密或叫编码算法。阅读文档时,Flash接受参数,由Flash动态的向服务器发送请求读取数据,一次加载一页或几页,经过解码最终展现出来。在这个过程中,用户浏览器缓存的只是Flash本身,没有数据。

例如:http://www.docin.com/p-562081174.html

<code><embed type="application/x-shockwave-flash" src="http://pics.wanlibo.com/players/DocinViewer.swf?rand=20130829" width="100%" height="100%" style="undefined" id="player" name="player" quality="high" align="middle" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" flashvars="productId=562081174&channel=0&loadurl=docin.oss.aliyuncs.com&aid=5&sgid1=1&sgid4=4&sgid3=3">
</embed></code>

他载入的数据是:http://docin.oss.aliyuncs.com/docin_562081174.docin

这个数据文件当然是加密的。

PS. 写在最后,我的答案可能文不对题,你是想要在现有的东西上解决问题。我是提出了另外的实现方式,实现还是有成本的。

你这种情况是不可能禁止通用浏览器(IE、Chrome、Firefox之类)缓存swf文件的,除非你开发定制版浏览器,或者开发一种新格式,用你特殊的插件播放。

要实现保密需求,可以用以下几个方面着手:

  • 流式播放,像各大视频网站一样,内容实际是在服务器端的,一段一段发送给浏览器端的,只在内存里,不在硬盘上。硬盘上的缓存文件只是个swf格式的播放器(player.swf)
  • 用php动态生成swf文件,文件里嵌入一个唯一标识码,绑定访问者的身份(如工号、内网IP、登录名),你缓存了不要紧,要是拿出去干坏事,那就能追查到泄密的源头在哪
  • 给每个swf套个壳(壳也是actionscript开发的swf),壳负责通过HTTP与服务器端交互,获取必要的授权才播放后面的office文档。与服务器端的授权交互可以让观看者参与(比如用账号登录),也可以不要求参与(比如验证IP,只有在内网才能播放)。如果有人把它拿回家,在请求服务器授权时就失败了
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
PHP's Purpose: Building Dynamic WebsitesPHP's Purpose: Building Dynamic WebsitesApr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side LogicPHP: Handling Databases and Server-Side LogicApr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO)How do you prevent SQL Injection in PHP? (Prepared statements, PDO)Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python: Code Examples and ComparisonPHP and Python: Code Examples and ComparisonApr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment