Joomla User login check

jsonx picture jsonx · Jul 17, 2010 · Viewed 11k times · Source

First I am not a joomla developer. My friend has a web site created with joomla 1.5. In webroot there are some joomla files. I created a directory in webroot "mydirectory" and i have an index file in this directory. I try to access joomla's user info in this page i grab the user object but it doesn't work.

 //i included joomla core  files
 $user =& JFactory::getUser();

 if ($user->get('guest')) {
     echo 'guest';
 } else {
 echo 'not guest';
 }

when I log in to my account, it says 'guest' again.

Also, I can't find anything in Joomla's session class.

$session =& JFactory::getSession();

Thanks

Answer

Martin picture Martin · Apr 13, 2011

You should do this:

$user =& JFactory::getUser();

if (!$user->guest) {
  echo 'You are logged in as:<br />';
  echo 'User name: ' . $user->username . '<br />';
  echo 'Real name: ' . $user->name . '<br />';
  echo 'User ID  : ' . $user->id . '<br />';
}

This is from here: http://docs.joomla.org/JFactory/getUser