Page 1 of 1
Check if CMSMS user (not FrontEndUser) is logged in
Posted: Fri Jul 10, 2009 1:23 am
by jmcgin51
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!
Re: Check if CMSMS user (not FrontEndUser) is logged in
Posted: Wed Apr 28, 2010 11:08 am
by kbh
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.
Re: Check if CMSMS user (not FrontEndUser) is logged in
Posted: Sat Dec 18, 2021 10:45 pm
by andrewvideouk
Do anyone know how to get this working on the lastest CMSMS. I try it and nothing happends.
Cheers
Re: Check if CMSMS user (not FrontEndUser) is logged in
Posted: Sun Dec 19, 2021 1:37 am
by DIGI3
Try this, it may require permissive_smarty in your config but I'm not positive:
Code: Select all
{$uid = get_userid(FALSE)}
{if $uid > 0}
admin user is logged in
{/if}
(note, this is just Smarty you can use in your content/templates, it's not a UDT)
Re: Check if CMSMS user (not FrontEndUser) is logged in
Posted: Sun Dec 19, 2021 2:06 pm
by andrewvideouk
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
Posted: Wed Jun 25, 2025 9:28 am
by brambaud
Hi,
In case anyone is looking for a simple solution to implement.
{if $smarty.session._userkey_ != ''}
Backend user connected !
{/if}