简体   繁体   中英

Apache, mod_cache and Cookies

I'm thinking about using mod_cache. However, the pages (generated by php) that I want to have cached by Apache usually contain the login name of that user (“You are logged in as ...”). So I cannot just cache a single page for all users.

The login state is determined by a cookie. So I thought that I could (in PHP) include a 'Vary: Cookie' header in every page. If my understanding of RFC 2616 is correct, this should instruct the Apache (or any other) caching algorithm to cache a separate page for every individual Cookie value that is sent by the user agent.

So if no cookie is sent by the browser (user is logged out), the cached response is kept separate from the cached response to a request with Cookie: state=89898XAAJ (user is logged in as 'Jacob') and that is again kept separate from a cached response to a request with Cookie: state=XXAIU2389 (user is logged in as 'Bob'). And if, some time later, a user requests the same URL and uses Cookie: state=89898XAAJ, he is served the correct page with 'You are logged in as Jacob' in it (and not the other cached ones).

Is my understanding correct and is this going to work this way or am I overlooking something here?

I'm not sure if the approach you've described will work or not.

If it doesn't, you could try checking the cookie value with a rewrite condition and redirect to the cached address based on the user and logged in status.

This page discusses rewriting based on cookie value:

Check cookie and redirect with Apache

Be Well,
Joe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM