The session variable must not be persisting properly.
Try changing line 23 from this:
if (!session_id()) session_start();
Then you could test if session variable setting and display is working in general. Can you set a session variable on one page and display it on the next?
It could be an issue with your php.ini file and the session_save_path folder or permissions on that folder.