Home  >  Article  >  Backend Development  >  A false statement about session failure

A false statement about session failure

巴扎黑
巴扎黑Original
2016-12-19 11:22:531030browse

I recently encountered a problem. An ajax request will call an existing session and then do some processing based on the session. I found that sometimes the session took effect and sometimes it didn't.

Session is saved to db, so there is no problem of session inconsistency caused by accessing different servers.
The page uses varnish. At first, I thought that varnish cached the page, causing the request to not be executed to php, but to use http cache. After clearing varnish, I still have this problem.

I cleaned up the requested page again and found that the simplified and traditional Chinese link in the header of the page uses the html suffix. This may be caching HTML, causing the page generated by clicking the link in this header not to actually generate a session. Naturally, there is no session to obtain the ajax of this cached page.

Okay. Here’s the solution:
1 Bring the session parameters into ajax and bring them with every request, so you don’t have to rely on the session for processing.
2 Change html to php. However, if varnish or other caching technology is used, it may also cause the above problems. Therefore, it is best to use the first method without relying on session.


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