Check if CMSMS user (not FrontEndUser) is logged in

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Check if CMSMS user (not FrontEndUser) is logged in

Post 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!
User avatar
kbh
New Member
New Member
Posts: 3
Joined: Mon Apr 26, 2010 3:57 pm

Re: Check if CMSMS user (not FrontEndUser) is logged in

Post 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.
Last edited by kbh on Wed Apr 28, 2010 11:17 am, edited 1 time in total.
andrewvideouk
Forum Members
Forum Members
Posts: 156
Joined: Thu Aug 20, 2020 10:49 pm

Re: Check if CMSMS user (not FrontEndUser) is logged in

Post by andrewvideouk »

Do anyone know how to get this working on the lastest CMSMS. I try it and nothing happends.

Cheers
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1789
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Check if CMSMS user (not FrontEndUser) is logged in

Post 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)
Not getting the answer you need? CMSMS support options
andrewvideouk
Forum Members
Forum Members
Posts: 156
Joined: Thu Aug 20, 2020 10:49 pm

Re: Check if CMSMS user (not FrontEndUser) is logged in

Post 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.
User avatar
brambaud
New Member
New Member
Posts: 9
Joined: Mon Apr 18, 2011 8:38 am

Re: Check if CMSMS user (not FrontEndUser) is logged in

Post by brambaud »

Hi,

In case anyone is looking for a simple solution to implement.

{if $smarty.session._userkey_ != ''}
Backend user connected !
{/if}
French CMSMS websites maker
Post Reply

Return to “CMSMS Core”