Had a project where I was editing existing code…always brutal. I had everything working in my development environment but when I went to deploy on production, I had an issue where the session was not reliably maintained. I had a “Welcome user” message that would appear in the header if a user was logged in and it appeared on some pages but not on others. The site uses Smarty templates so I thought it was a problem with caching or with Smarty templates not having access to the $Smarty.session variables for some reason.
I went to bed and got up in the morning with a fresh set of eyes. Turns out the code had a WWW_URL value set which included the “www”. So the user would start at http://example.com and then as they stepped through the code would be sent to http://www.example.com. Well sessions are tied to the domain name and so a different session is set at http://www.example.com pages than is set at http://example.com. So I had two active sessions at the same time. I changed the WWW_URL to http://example.com and now it all works.