We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18289
    • 4 Posts
    Hello! I am developing a site using modx, plus an external db and a group of pages with their own functionality.
    I have a large db with login and pwds, and I need to show documents contained in modx. The modx part is ok, under control, but I need to add authentication before showing each document. The user authenticated sets the sessions variables, so It would be ideal to be able to access these variables when loading a modx document to show or redirect the page.
    I have tried to add this functionality, but modx can’t see any session variables set outside.. any ideas please?
    Thanks
      • 16281
      • 1 Posts
      Hi, I am having exactly the same problem. I logged in to aMember (external db etc), and then opened a php page with the following code:

      <?php
      session_start();
      $user = $_SESSION[’_amember_user’];
      if ($user[’member_id’] > 0){
      print "Hello $user[name_f] $user[name_l]
      \n";
      print "Your E-Mail address is $user[email]
      \n";
      } else {
      print "You are not logged-in";
      }
      ?>

      and it returned username etc.

      I opened a page using the same code in a snippet in MODx and I get ’You are not logged-in’

      Am I putting the session_start(); in the wrong place somehow?

      Thanks.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        MODx has its own session with its own name (see the config.inc.php file for the name of the sessions for your installation). It sounds like you have two different sessions going, one for your app and the one for MODx. The snippet is using the session started for MODx. You can use the MODx session file in your app by setting the same session_name that MODx is using.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org