How to check backend user is logged in?

243 views
Skip to first unread message

shaoen01

unread,
Jan 20, 2014, 8:00:59 AM1/20/14
to joomla-de...@googlegroups.com
Hi,

I would like to find out how do i find out if a backend user is logged in via a front-end model in Joomla? I tried using the JFactory::getUser(), but it does not work for getting backend users logged in from the front-end? Thanks

Appreciate any help.

Mark Dexter

unread,
Jan 20, 2014, 10:53:33 AM1/20/14
to Joomla! General Development
I don't understand your question. getUser() tells you about the current user. It sounds like you want to see a list of all users and where they are logged in. Is that right? If you look at the module mod_logged you can see one way to get such a list. See administrator/modules/mod_logged/helper.php.

Good luck. Mark


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/groups/opt_out.

shaoen01

unread,
Jan 20, 2014, 5:47:32 PM1/20/14
to joomla-de...@googlegroups.com
Hi Mark,

Thanks for the response. What is happening is that:

1. Backend user logins.
2. Backend code calls a front end file via Ajax.
3. The front end file tries to access the user that is currently logged in. However, because of the front-end file it can't detect the backend user logged in.

So what i am trying to find out is if it is possible to detect the current user logged in from the front end. if the current user actually logged in from the backend. I hope this makes some sense, appreciate any advise.

I am actually continuing the work of an extension done by someone. So just wondering if this can be done technically? Thanks


On Monday, 20 January 2014 23:53:33 UTC+8, Mark Dexter wrote:
I don't understand your question. getUser() tells you about the current user. It sounds like you want to see a list of all users and where they are logged in. Is that right? If you look at the module mod_logged you can see one way to get such a list. See administrator/modules/mod_logged/helper.php.

Good luck. Mark
On Mon, Jan 20, 2014 at 5:00 AM, shaoen01 <shao...@gmail.com> wrote:
Hi,

I would like to find out how do i find out if a backend user is logged in via a front-end model in Joomla? I tried using the JFactory::getUser(), but it does not work for getting backend users logged in from the front-end? Thanks

Appreciate any help.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.

Mark Dexter

unread,
Jan 20, 2014, 6:23:48 PM1/20/14
to Joomla! General Development
What is the "front end file"? Is that your code or someone else's (e.g., core or another extension)? If it's your code, you could use something similar to the code I referenced earlier to get a list of all logged in users and figure out whether this is one of them. Or maybe you could use a session token to eliminate the need to login in the front end.

If the code is something you can't change, then one option might be to just log into the front end of the site automatically, using the back-end credentials. 

Good luck. Mark


To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.

Valerie Pooh

unread,
Jan 20, 2014, 6:57:38 PM1/20/14
to joomla-de...@googlegroups.com
Hi Mark,

Trying to modify an existing extension done by another developer. By front end file, i mean not within the "administrator" folder.

I tried the following code in my front-end file with reference to mod_login
$user = JFactory::getUser();
$user->get('username')

I get no value.

I looked at my PHPMyAdmin on my prefix_session table and found 2 sessions. One is the logged in session from the backend login and another on the front-end as guest.

What i would like to do is to find out who is the current logged in user of the backend via the frontend file. Appreciate your help. Thanks

Regards,
Valerie


--
You received this message because you are subscribed to a topic in the Google Groups "Joomla! General Development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/joomla-dev-general/F1-F6lExbB4/unsubscribe.
To unsubscribe from this group and all of its topics, send an email to joomla-dev-gene...@googlegroups.com.

Mark Dexter

unread,
Jan 20, 2014, 7:12:44 PM1/20/14
to Joomla! General Development
Sorry, I'm still a bit confused. What if you have multiple users logged into the back end? Would it make sense to pass something in the request, such as a session token and the user id? It seems that somehow you need to tell the front-end program that who you are instead of trying to guess after the fact. But maybe I'm missing something basic here. Mark

Sven

unread,
Jan 21, 2014, 3:46:40 AM1/21/14
to joomla-de...@googlegroups.com
1. If you try to modify an extension, why you don't do it the way it's supposed to be?
2. What exactly are you trying to do/modify, to be more precise, why you want to modify a back-end file from a front-end file?
3. The front-end and back-end of Joomla do not share the session, that means, if you login to the front-end and the back-end you will find 2 db entries in your session table, like you did already, one for front-end and one for the back-end, that is why you not get the value you want.

Well, your last sentence makes a bit of sense and also is easy to answer^^
I wrote "a bit" for a reason: 1) there could be no logged in admin user. 2) there could be more than once. or 3) only one is logged in.
You just need to make a database call to the session table with left join on users table to get name etc you want.
SELECT s.userid, u.username FROM #__session as s LEFT JOIN #__users as u on u.id = s.userid WHERE s.client_id = 1;

Valerie Pooh

unread,
Jan 23, 2014, 10:20:20 AM1/23/14
to joomla-de...@googlegroups.com
Hi both,

I guess my purpose is to allow backend login users to use a functionality offered to the front end, so that they have the flexibility of login. Checking of permission will be performed.

Because of the differentiation between front end and backend login, this makes it difficult.

However, from your responses, triggered an idea and it works. I will do an Ajax call to my front end functionality and pass an indicator to acknowledge that this backend user has the permission to do so.

Thanks both!
--
You received this message because you are subscribed to a topic in the Google Groups "Joomla! General Development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/joomla-dev-general/F1-F6lExbB4/unsubscribe.
To unsubscribe from this group and all of its topics, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/groups/opt_out.


--
Regards,
Valerie

shant...@tekdi.net

unread,
Feb 11, 2014, 4:44:09 AM2/11/14
to joomla-de...@googlegroups.com
Hello,

You can define access for back end users. If you define that only super users will login, then no need to check who is logged in.

Reply all
Reply to author
Forward
0 new messages