How to check user is logged in Joomla site ?


You can check Joomla user logging status using the JUser Object of JFactory class.

<?php
//First assigned user object to $user variable
$user = & JFactory::getUser();

//Method 1
//Check guest property of the user object, if it is 1 then user not logged in Joomla
if ($user->guest) {
echo “Please login in site.”;
} else {
echo ‘welcome ‘ . $user->name . ‘ !!’;
}

//Method 2
//Check user id is zero, if it is zero means user not logged in Joomla
if ($user->id == 0) {
echo “Please login in site.”;
} else {
echo ‘welcome ‘ . $user->name . ‘ !!’;
}

//Method 3
//Direct check the guest property without using the $user object
if ( JFactory::getUser()->guest) {
echo “Please login in site.”;
} else {
echo ‘welcome ‘ . $user->name . ‘ !!’;
}

?>

Advertisements

3 thoughts on “How to check user is logged in Joomla site ?”

  1. My coder is trying to persuade me to move to .net from
    PHP. I have always disliked the idea because of
    the costs. But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for
    about a year and am nervous about switching to another platform.
    I have heard good things about blogengine.net. Is there
    a way I can import all my wordpress content into it?

    Any help would be greatly appreciated!

    1. WordPress is the leading blogging and content management solution in open source. There is so many plugin already developed and most of them are available under GPL ,so you can use them in your site.

  2. Hi to every one, it’s genuinely a pleasant for me to go to see this web page, it contains helpful Information.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s