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

    i try to make a snippet (named "autorisation"), which add (or not) special content on a page if user is login via the managerLogin snippet and belong to a specific user group (or not) .
    So if you’re logged as an manager user you can see more content, depends on which group you belong to.

    the snippet work fine...but not the first time.
    I explain.
    I’m not login -> extra content don’t appear. And that’s what i want!
    login via managerLogin -> manager Login snippet show the logged template. Yes I’m login, but no extra content appear embarrassed
    press F5 -> my extra content appear, at last.
    same thing when i want to logout.
    logout via managerLogin -> extra content still appear.
    refresh the page (F5) -> extra content finally disappear.

    The managerLogin uses to test $_SESSION[’mgrValidated’] to now if a user is login or no, like i do in my snippet. Why should i have to refresh the page after login or logout to have the good content on my page huh

    Here is my "autorisation" snippet code
    $autorised = false;
    if (isset ($_SESSION['mgrValidated'])) {
       $uid = $_SESSION['mgrInternalKey'];
       $result = modx->db->query("SELECT name FROM `modx_member_groups` as m LEFT JOIN `modx_membergroup_names` as n ON m.user_group = n.id WHERE member = '".$uid."'");
       $names = mysql_fetch_assoc($result);
       do{
           if($names['name'] == $groupe)
               $autorised = true;
               break;
           }
       }while($names = mysql_fetch_assoc($result));
    }
    return $autorised;
    


    And here is the order, things came in my page.
    first managerLogin call in the page template. In the content of the page i call a snippet (uncached) which call (via runSnippet) my snippet "autorisation".

    If someone could help... rolleyes

      • 4041
      • 788 Posts
      Apparently the manager login snippet you are using does not refresh the page like the weblogin snippet does.
      Your session variables are not accessible until the next page you visit after logging in, if I’m not mistaken.
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 3749
        • 24,544 Posts
        I’m not an expert on sessions, but it’s possible that the session variables are being created, just not fast enough.

        Two things might help.

        Create the session variables at the start of your script by setting them to "". That way, when you write to them, you won’t have to wait for the server to create them.

        Second, calling session_write_close() after writing the session variables could help.



          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 21026
          • 53 Posts
          Thank you for your response

          in fact when i said
          the snippet work fine
          you must read :" the snippet code is full of errors" shocked

          And... once the errors fix... the problems with $_SESSION has gone!!! grin


            • 3749
            • 24,544 Posts
            Been there. wink

            Glad it worked out.

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting