W3bbo said:
lesmemphis said:

Save a copy of the generated markup from both production and development, ensure it validates, then run a diff. Then report back your findings.

It seems the problem was to do with sessions. Sometimes when I call a variable in a session it returns a null, but if I just call it again, it returns the value. So now I just build a check in. Haven't had the problem since. Still holding fingers crossed that it won't happen again.