I know how to check to see if a frontend user is logged in, but how do I check to see if a backend user is logged in? In other words, I want to only display content in the frontend if the user is logged in to the backend. I think the {edit} tag did this once upon a time. I took a look at the {edit} php function, and couldn't tell exactly how to adapt the login check to a more general-purpose use.
I'm hoping there's a simple tag I can use in a page, like {if $backend->logged_in()}blah{/if}.
Thanks!
Check if CMSMS user (not FrontEndUser) is logged in
Re: Check if CMSMS user (not FrontEndUser) is logged in
You can create a User Defined Tag (UDT) that checks if a session exists for the current user, like this:
1) Create a UDT named "user_logged_in":
// Returns an Integer (1-99999) if user is logged in.
if (isset($_SESSION["cms_admin_user_id"])) {
echo $_SESSION["cms_admin_user_id"];
// You can also check on $_SESSION["login_user_id"].
}
2) You can now use the UDT-script as a Smarty-variable on your Templates and Pages:
{capture assign='user_logged_in'}{user_logged_in}{/capture}
{if $user_logged_in>0}My little secret.{/if}
Notice, the $_SESSION-trick only works inside CMS Made Simple while it fails on external PHP-pages.
1) Create a UDT named "user_logged_in":
// Returns an Integer (1-99999) if user is logged in.
if (isset($_SESSION["cms_admin_user_id"])) {
echo $_SESSION["cms_admin_user_id"];
// You can also check on $_SESSION["login_user_id"].
}
2) You can now use the UDT-script as a Smarty-variable on your Templates and Pages:
{capture assign='user_logged_in'}{user_logged_in}{/capture}
{if $user_logged_in>0}My little secret.{/if}
Notice, the $_SESSION-trick only works inside CMS Made Simple while it fails on external PHP-pages.
Last edited by kbh on Wed Apr 28, 2010 11:17 am, edited 1 time in total.
-
- Forum Members
- Posts: 156
- Joined: Thu Aug 20, 2020 10:49 pm
Re: Check if CMSMS user (not FrontEndUser) is logged in
Do anyone know how to get this working on the lastest CMSMS. I try it and nothing happends.
Cheers
Cheers
Re: Check if CMSMS user (not FrontEndUser) is logged in
Try this, it may require permissive_smarty in your config but I'm not positive:
(note, this is just Smarty you can use in your content/templates, it's not a UDT)
Code: Select all
{$uid = get_userid(FALSE)}
{if $uid > 0}
admin user is logged in
{/if}
Not getting the answer you need? CMSMS support options
-
- Forum Members
- Posts: 156
- Joined: Thu Aug 20, 2020 10:49 pm
Re: Check if CMSMS user (not FrontEndUser) is logged in
Thank you that worked. Looks like I added permissive_smarty in my config already. loosens some of the security configuration for smarty templates.
Can't remember why I did it. Might remove it later and see what breaks lol.


Re: Check if CMSMS user (not FrontEndUser) is logged in
Hi,
In case anyone is looking for a simple solution to implement.
{if $smarty.session._userkey_ != ''}
Backend user connected !
{/if}
In case anyone is looking for a simple solution to implement.
{if $smarty.session._userkey_ != ''}
Backend user connected !
{/if}
French CMSMS websites maker