We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36467
    • 73 Posts
    I am developing custom manager page with two files index.php and ajax.php. Index.php is a page which shows up in manager panel, from index.php page i call ajax.php via ajax call.

    Problem is that, if i write below code in index.php i get logged in user id but when i use same code in ajax.php file it return 0 as logged user it. I even tried to pass id inside session, but again i dont see session variable in ajax.php.

    If i dont check if user is logged in, then anyone can access ajax.php page.
    How can i check is user is logged in and has manager access in ajax.php ?

    require_once '../config.core.php';
    require_once MODX_CORE_PATH.'model/modx/modx.class.php';
    $modx = new modX();
    $modx->initialize('mgr');
    retun $modx->getLoginUserID();
    

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Two possibilities - I am sure that there are many more.

      1. Put your AJAX code in a snippet and put the snippet tags in a protected resource.
      2. Create a folder in core/components for your CMP, and keep your files in there. Nobody can access the files in the core.
        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
        • 36467
        • 73 Posts
        Sottwell : thank for reply. Regarding your solutions
        1) To explain the scenario in short i said i have 2 files, in fact i have quite complex code with many files. So putting ajax code in a snippet will take lot of time and not sure at the end it will work or not.
        2) I moved code from core/components i still can access pages without logging in.

        To shorten my problem : What i want to achieve is, somehow i want to access logged in user id in ajax.php. That will solve my problem.
          • 36467
          • 73 Posts
          Is there any way i can access logged in users ID or just some session flag that ensure me that user is logged in with manager access using MODX api outside modx ?