After setting a session, if you locate to another page using a header() call, you need to restart the session in the page which you go to.
Consider this code:
$_SESSION['name'] = "LearningCoder";
and now this is the file which I locate to with a header() call:
OK. Load up code number one - call it whatever you like. Rename the second code as file.php
Notice, when you load up the first code, you locate to the file.php page and the session displays.......
Now take out the session_start() from the second code...
Notice you get the undefined error.
Just add session_start() into your second code.