How to force clear user's cache/cookies?

南楼画角 提交于 2021-01-02 05:47:18

问题


Is there any way to force clear users cache and/or cookies? Especially in Safari/Webkit.

Many thanks!


回答1:


Yes. Trick the user into selecting the appropriate menu item which clears their cookies and cache. I kid! That would be called "social engineering" type of hacking and is inadvisable for those wishing to stay clear of legal troubles.

There are a couple of tags that may be useful, depending on what you want to do:

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="Refresh" CONTENT=...time>

This only controls your own web page, not the cache in general. Of course, you can set your own site's cookies to whatever you want.




回答2:


No, presuming that you want to clear ALL of it. The only cookies you can clear are the ones with "path" and "domain" attributes matching to your own application. The browser doesn't send the server anything else and it would be a serious security flaw if it did. Similar logic applies to client-side scripting.

However, all lights are green if you simply want to manage caching and cookies in the context of your own application. Caching can be turned off by sending relevant HTTP headers along with the response:

Cache-Control: no-cache, must-revalidate
Expires: Thu, 1 Jan 1970 00:00:00 GMT
Pragma: no-cache

Clearing a cookie comes down to setting it's expiration date into the past. A browser does not send out expired cookies.



来源:https://stackoverflow.com/questions/3794532/how-to-force-clear-users-cache-cookies

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