We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28376
    • 222 Posts
    I was wondering how do i pass URL variables into a snippet when doing a call like this

    [ [mySnippet? &width=`100` &height=`300` ] ]


    so basically width and height will be passed as

    index.php?width=200&height=100

      • 22303 MODX Staff
      • 10,725 Posts
      $_GET and $_POST variables work in MODx like they would in any PHP site, though you must not cache snippets that must use them dynamically. You would not explicitly pass them in the snippet call.
        • 28376
        • 222 Posts
        That worked but the php code i have here it doesn’t change the user on the next page refresh any ideas as to why?

        <?php
        $rusr="";
        $rpwd="";
        
        $modx->clearCache();
        
        $rusr=$_GET['usr'];
        $rpwd=$_GET['pwd'];
        
        echo "username:  ".$rusr;
        
        function login($username, $password)
        {
           global $modx, $table_prefix;
           $username = $modx->db->escape($username);
           $password = $modx->db->escape($password);
           $table_prefix="kdb";
         
           $res = $modx->db->select("id", $table_prefix."_web_users", 
              "username='$username' AND password='".md5($password)."'");
           if($modx->db->getRecordCount($res))
           {
              return "sucess";
              //other log in things...
           }
           else
           {
               return "fail";
           }
        }
        
        
        echo login($rusr,$rpwd);
        ?>
        
          • 22303 MODX Staff
          • 10,725 Posts
          You caching it? Also, $modx->clearCache() is meaningless TBH; no need to use it. You need to make the page non-cacheable or call the snippet with non-cacheable tags, i.e. [!Snippet!] vs. [[Snippet]].
            • 28376
            • 222 Posts
            It was the caching issue. Thanks so much