Check if user is logged in in Joomla 1.5.x

Use the code below to check if a user is logged in. This is useful if you want to only show certain parts of your component to registered users and not non-registred users. Have fun.

$user =& JFactory::getUser();
if($user->id)
{
    //do user logged in stuff
}
else
{
    //do user not logged in stuff
}