We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31782
    • 103 Posts
    I clicked on the link and open a new page of my site.
    How can I transfer id of the previous page to the new page?
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Several options coming to mind...

      * Append the current ID as a GET parameter to every link on your site (ie otherpage.html?prev=43). Doesn’t look pretty imo.
      * Check the HTTP_REFERER to see where they came from. Doesn’t always work as some user agents don’t set it.
      * Set a cookie or $_SESSION var on every pageload with the ID of the page it’s on. You can check it from there then.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 31782
        • 103 Posts
        Thank you Mark.
        Your solutions are suitable in general for all PHP sites.
        Are there any solutions used in MODx? For example, transmission id in the TV?
        I tried GetField snippet, but I do not understand how to apply it for my case.
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          A template variable is used to set information for a specific page - not a specific user/session/pageview.

          Maybe you should tell us more about your specific case? I assumed you just want to track what was going on.


          And don’t forget MODX is built on PHP smiley You can very easily make a snippet that checks a $_SESSION var & sets it with the current resource ID.

          For example:
          // Check if it's set, and if so set the ID to a placeholder to use in a template for example
          if (is_numeric($_SESSION['prevpage'])) { $modx->setPlaceholder('prevpage',$_SESSION['prevpage']); }
          }
          // Set the prevpage var to the current resource ID (Revolution-style) so you can check it on the next pageview
          $_SESSION['prevpage'] = $modx->resource->get('id');


          Just put that code in a snippet, and call the snippet somewhere on your page.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 31782
            • 103 Posts
            Just put that code in a snippet, and call the snippet somewhere on your page.
            If I call this snippet then get a white page.
            Of course, I corrected the mistake with the bracket. I tried the operator "else" and instead is_numeric ($ _SESSION [’prevpage’]) use only $ _SESSION [’prevpage’], the result is a white page.
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              The snippet should set a placeholder [+prevpage+] - you’ll also need to put that somewhere.

              Sorry for forgetting to mention that!

              You could also change the snippet to just return the value with
              return $_SESSION['prevpage'];


              May be more logical..
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 31782
                • 103 Posts
                Many thanks, Mark. This works fine.

                I should add that I`m using MODx Evo and slightly modified the code:
                <?php
                // Check if it's set, and if so set the ID to a placeholder to use in a template for example
                if (is_numeric($_SESSION['prevpage'])) { $modx->setPlaceholder('prevpage',$_SESSION['prevpage']); }
                
                // Set the prevpage var to the current resource ID (Revolution-style) so you can check it on the next pageview
                $_SESSION['prevpage'] = $modx->documentObject['id'] ;
                return $_SESSION['prevpage'];
                ?> 


                Two small problems:
                1. The snippet displays the ’id’ and on the previous page and next. On this second page displays and its id (in place the snippet) and id of the previous page (in place a placeholder). If I commented return $_SESSION[’prevpage’]; - snippet not work.
                2. Now complicate the task smiley Try to pass content. Change $modx->documentObject[’content’], but it does not work now.
                  • 31782
                  • 103 Posts
                  2 problem solved. is_numeric smiley
                    • 31782
                    • 103 Posts
                    1 problem solved. Need to deleted return $_SESSION[’prevpage’];

                    Thanx
                      • 18373 ☆ A M B ☆
                      • 3,141 Posts
                      Your welcome smiley

                      Glad you got it working & shared your solution for Evolution!
                        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.