1) Read the manual about sessions (again if necessary)
2) session_register is only to enter a new variable into a session. You do not have to register a variable if just want to get the variable from the session.
3) The error you get is logical. The first time you use the session it's empty, so $sess_loggedin does not exist.
You use session_register() to register $sess_loggedin, but new variables are not put into the session until the script is ended, so it is not immediately available.
After checking if $sess_loggedin exists, you set it to false, so when the script end the variable $sess_loggedin is entered into the session.
So the second time you access it, the session does contain the $sess_loggedon var, and you don't get the error.