We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18800
    • 2 Posts
    Hi all,

    first time here, and having difficulty finding my way around. I have searched every term
    I can think of, but gotten nowhere.

    What I’m looking for is the simple variables or cookies to check whether a web user is logged
    in. Would someone please post them?

    I want to restrict access to a directory to only logged-in members, and am struggling with the
    .htaccess, which has always been a weak point. I’ve got to the point of sending users to a log-in
    page, but can’t find how to check variables.

    many thanks in advance,

    Duncan
      • 33968
      • 863 Posts
      Hi, welcome to MODx!

      Are you using Revolution?

      Unless I misunderstood, you could have a go at setting User Permissions which should allow you to restrict access to certain parts of your site.

      Also - a new forum with improved search is coming soon, but for now you will get much better search results from Google instead. Try site:modxcms.com/forums ’your query here’
        • 18800
        • 2 Posts
        Thanks for your response, yes, I’m using revolution, the version info says "rev 6066". and thanks for the tip re search, difficult to find complete documentation for a beginner.

        I was trying to restrict access to a /directory/ based on whether or not the user was logged in. This is how I ended up doing it, in .htaccess;

        <code>
        # Cookie Directory Protection
        RewriteCond %{REQUEST_URI} ^/pdfs/(.*)$
        RewriteCond %{HTTP_COOKIE} !SN4c56177e7b9f6=([^;]+) [NC]
        #RewriteCond %{HTTP_COOKIE} !WebLoginPE=([^;]+) [NC]
        RewriteRule . /member-check.html [L]
        </code>

        I couldn’t find a better way to check whether the user is logged in than the site’s cookie name, SN4c56177e7b9f6.

        Member-check is an adapted version of the webloginpe snippet. I’ve also fiddled with that .class.php file to direct a user to the pdf once logged in, instead of the to the front page.

        The above is probably a hideous mess, but I’m a mod-x beginner, and had deadline pressure.

        cheers,

        Duncan
          • 33968
          • 863 Posts
          If you’re using rev 6066 then it is actually Evolution. That’s been sorted out in the latest version of Evo but has definitely caused a bit of confusion!

          I take it that you found a solution to securing the file downloads. I’ve not tried anything similar yet, but there are also a number of add ons for Evolution that might assist you in future, depending on your site setup:

          FileDownloadPE
          FileDownload

          You can also use LoggedOrNot to display different content depending on, well, whether a user is logged in or not. If you are putting your own snippet together, have a look at the API Reference as there are some functions already set up to help you.