We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7205
    • 9 Posts
    Simple question:

    I’m using web users. I want to use php inside of my pages for custom code. I want to be able to know if someone is logged in. For example, if someone is logged in I want to display their information. How can I use php inside of my pages and how do I check to see if someone is logged in? I tried using

    [tt]<?php
    echo getLoginUserName( );
    ?>[/tt]

    in one of my pages but the php wasn’t parsed. Please help. Thanks!
      • 7231
      • 4,205 Posts
      PHP needs to be put in a snippet to be rendered.

      There are a few snippets that will provide the user info placeholders. Here is one (I have not tested this yet):
      http://modxcms.com/UserPlaceholders-1596.html

      I have also seen one that will display a chunk if logged in but I can’t remember the mane at the moment.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 7205
        • 9 Posts
        Thanks dev_cw. I had just figured this out. You have to use snippets to do PHP and the API functions need to start with $modx->. So, I created a new snippet that looks like this and it works:

        [tt]
        <?php
        echo $modx->getLoginUserName( );
        ?>
        [/tt]