Yes that line is in register.php, but I mean that $reg hasn't been assigned to anything. If you enable your error reporting:
You should trigger the error:
Notice: Undefined variable: $reg in xx/register.php on line ?
Therefore assigning $_SESSION['user_id'] to null. Null will not pass an isset check, so the loggedin will return false.