We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4095
    • 372 Posts
    Is there a varibale in MODx that will tell you what the URL of the referer was?

    I want a user to click on a link which will take them to a page that’ll display some code which is based on where the page URL they just came from.



      [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
      Admin Sandbox Login: sandbox Password: castle
      • 4095
      • 372 Posts
      I came across and easy solution while trying to figure soemthing else out.

      Just create a snippet as below caled "Referer" and then use as follows:

      You were sent here by [!Referer!]

      $output .= $referer = $_SERVER['HTTP_REFERER'];
      return $output;
      
        [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
        Admin Sandbox Login: sandbox Password: castle
        • 6726
        • 7,075 Posts
        Nice and simple, yet pretty useful !

        Thanks for this one smiley
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l'outil id
          • 4095
          • 372 Posts
          Quote from: davidm at Jan 15, 2006, 10:31 PM

          Nice and simple, yet pretty useful !

          Thanks for this one smiley

          Now to add to it, need to get the page title from the previous page.

          Only way I can find to do it is use the previous URL with a ? and add some stuff like www.domain.com?title=homepage

          Then use an array to $GET the "title= ". Only thing is I don’t want to alter the URL at all. Not sure if MODx can store a variable from a previous page to be called later elsewhere in the site?
            [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
            Admin Sandbox Login: sandbox Password: castle
            • 18397
            • 3,250 Posts
            You can use a URL strip function to get everything after the domain name from a referrer so you can have your title.
              • 4095
              • 372 Posts
              Quote from: Mark at Jan 16, 2006, 12:40 AM

              You can use a URL strip function to get everything after the domain name from a referrer so you can have your title.

              The Page title and url may be different though, especially in my case with FURL’s. Its only for use inside the site.

              I thought about using a TV or something to set a global variable to the pagetitle then using the snippet to retrieve it on the page I want. Each page would replace the global variable so only the last one would be there.

              The page that uses the snippet wouldn’t use the TV so it won’t mess up the snippet.

              Problem is I can’t even get the placeholder to work. Just to test it I tried a snippet with.

              $modx->setPlaceholder($RefererTitle, $id);
              Then using [+RefererTitle+] to show it on a page, but no such luck.
                [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                Admin Sandbox Login: sandbox Password: castle
              • Quote from: briggsys at Jan 15, 2006, 10:38 PM

                Not sure if MODx can store a variable from a previous page to be called later elsewhere in the site?
                MODx doesn’t provide persitent values across requests, but PHP does. Set a session variable on a page like this...
                $sessionVarKey= 'varName';
                $value= 'valueYouWantToPersistAcrossRequests';
                $_SESSION[$sessionVarKey]= $value;

                and then collect the value from it on any other page...
                $valueRetrievedFromSession= isset($_SESSION[$sessionVarKey])? $_SESSION[$sessionVarKey]: null;

                or something similar.
                  • 4095
                  • 372 Posts
                  I’m having some trouble here, which will have a lot to do with the fact I have NO idea what I’m doing and 6 hours of trail an error is getting frustrating laugh


                  Page 1 has a snippet to called [[GetPageTitle]] which does exactly that, and then stores it in a session variable called GetPageTitle

                  $_SESSION[$GetPageTitle]= $modx->documentObject['pagetitle'];


                  The when I go to Page 2 I have a snippet called [[referer]] which should tell me the URL from Page 1 and its title.

                  $referer = $_SERVER['HTTP_REFERER'];
                  $RefererPageTitle = isset($_SESSION[$GetPageTitle])? $_SESSION[$GetPageTitle]: 'Not Set';
                  
                  $modx->setPlaceholder($RefererTitle, $RefererPageTitle);
                  
                  $output .= $referer;
                  return $output;
                  


                  It grabs the session variable GetPageTitle and gives it to a new variable called RefererPageTitle, otherwise displays "Not Set".

                  So far it all works.

                  This new variable should set a placeholder call RefererTitle which I can place on a page with [+RefererTitle+]

                  The Probelm is the placeholder doesn’t get the new variable or display "Not Set", however if I display it straight to the page I can see the page title which was set from Page 1.

                  $output .= 'Title = '.$RefererPageTitle;
                  return $output;
                  


                  Therefore I must be doing something wrong with setting the place holder?

                    [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                    Admin Sandbox Login: sandbox Password: castle
                  • Try $_SESSION[’GetPageTitle’] instead of $_SESSION[$GetPageTitle]

                    Put this in your snippets to check what is actually getting passed in that SESSION value:

                    echo "<pre>";
                    print_r($_SESSION);
                    echo "</pre>";
                      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
                      • 4095
                      • 372 Posts
                      Ok fixed it..... user error wink

                      $modx->setPlaceholder('placeholder',$variable)' 


                      not

                      $modx->setPlaceholder($placeholder,$variable);	


                      EDIT: Sottwell, you posted while I was typing the above; although I had already fixed the issue, I made the change you suggested.
                        [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                        Admin Sandbox Login: sandbox Password: castle