Home >Backend Development >PHP Tutorial >A false statement about session failure
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.