A must-read story if your PHP session keeps losing weirdly
by Hui Wang
I realize that there are numerous scattered posts on the PHP SESSION LOST issu, but I’d like to add my story since it took me almost two days to figour out that php session is lost but it’s not PHP’s fault.
In the very beginning, I thought the reason why my php session is lost is because of my incorrect php code. On lots of forums and blogs, people say that session_start() should be put in the very first line of each page, session_write_close() should come before the header redirect and also make sure that session_save_path is set in php.ini file. Without lucks, none of these tips could help me solve my problem.
Until the minute where I tried with another browser, I found out that it’s not php’s fault. My program worked like a charm in IE7. But it failed time and time again when the code met Firefox or Chrome. I became doubting on something that is browser-dependent.
Maybe IE and Firefox treat my HTML codes in different manners. I admit that there are indeed some breaks in my HTML. For instance, I get several elements of which the tag value is NULL because of intact data record in database. Something like <script src=”"></script> may appear in the HTML code. Almost hopelessly, I tried to remove these breaks. Surprisingly, my php session stopped losing.
Although I don’t know why the broke HTML code could affect PHP’s session management, I learned a big lesson that no matter how dynamically php could power your site, HTML is the very BASE.
Comments
[...] A must-read story if your PHP session keeps losing weirdly | Hui Wang [...]