5 Replies Latest reply on Sep 21, 2007 4:33 AM by futurewebservices

    How to set KT_REFERRER session variable for login redirect

      Hello!

      I have a "login" link at the top of each page in my site (and various content on the pages hidden by "show if user is logged in" behavior.) This link takes you to my "login.php" page where the user enters their username/password and logs in.

      I want to be able to return the user to the page
      b where they first clicked "login",
      NOT the default redirect page I setup in the ADDT login settings.

      From what I understand, I'm trying to simulate the behavior when a user tries to access a protected page: They're first redirected to the login page and then returned to where they were first going after they successfully login.

      SO, (i think) I need to somehow set the KT_REFERRER session variable to the current URL
      b BEFORE
      I send the user off to the login.php page. With that variable set, the login page should automagically take the user back to where they came from.

      I've tried changing the redirect trigger on the login page to:
      >$loginTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "
      b {KT_REFERRER}
      ");

      but that doesn't work because I don't think KT_REFERRER is being set by the previous page in the first place.

      any ideas?

      Thanks!

      ~shawn
        • 1. Re: How to set KT_REFERRER session variable for login redirect
          Günter Schenk Level 4
          Hi Shawn,

          interesting !! Some ideas:

          1. I don´t think it would be good to replace the login´s page default "{kt_login_redirect}" with "{KT_REFERRER}" -- when the user logs in 1st time, he will have to be redirected to what´s been defined in ADDT settings.

          2. If any, I would implement a PHP if-else here, which will be checking whether the {KT_REFERRER} variable exists (aka "isset"), and provide 2 different redirection targets, e.g.

          if (isset( {KT_REFERRER} )) {
          $loginTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "{KT_REFERRER}");
          }

          else {
          $loginTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "{kt_login_redirect}");
          }

          However, I´m not sure this will work, but let´s work on that, ok ? :-)

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: How to set KT_REFERRER session variable for login redirect
            Level 1
            Hi Gunter!

            Thanks for the quick reply!

            Indeed, I do need to handle the case when a user accesses the login.php page directly. Sending them to the default page is obviously fine in this case.

            On second thought the redirect behavior when "restrict access to page" is applied is exactly what I'm looking for. Somehow this behavior "tells" the login page to "come back here" instead of redirecting to the default page.

            I thought maybe just having the KT_REFERRER session variable set may do the trick, so I set this at the top of each page in the site:

            >$_SESSION['KT_REFERRER']=KT_getFullUri();

            So whenever anyone accesses a page, their referrer session variable is updated with their current URL. (this seems like an "expensive" solution, but maybe it's still pretty efficient?)

            I then changed the redirect back to the original:

            >$loginTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "
            b {kt_login_redirect}
            ");

            BUT, even with the KT_REFERRER variable set, after logging in, I'm sent to the
            b default
            redirect page, not to the KT_REFERRER. So there must be *something else* that tells the login page to redirect to KT_REFERRER instead of the default.

            Any idea what this might be? Maybe the "DENIED" bit in the URL?

            Thanks for your help!
            • 3. Re: How to set KT_REFERRER session variable for login redirect
              Günter Schenk Level 4
              Hi Shawn,

              >>
              Any idea what this might be? Maybe the "DENIED" bit in the URL?
              >>

              I´m sure you´re right with your assumption -- guess that KT_getFullUri(); just transfers everything incl. the DENIED part

              >>
              On second thought the redirect behavior when "restrict access to page" is applied is exactly what I'm looking for. Somehow this behavior "tells" the login page to "come back here" instead of redirecting to the default page
              >>

              wow, even I wasn´t really aware of that, never used "restrict access to page" in my pages so far.

              OK, well, then I d´just use that -- gotta go sleep now :-)

              Cheers,
              Günter Schenk
              Adobe Community Expert, Dreamweaver
              • 4. Re: How to set KT_REFERRER session variable for login redirect
                Level 1
                b SOLUTION:

                Okay, so I don't want to restrict access to the entire page, just simulate the action when this server behavior
                b is
                applied to a page.

                After a couple of hours tracing code, the two session variables that need to be defined are:

                >$_SESSION['KT_denied_pageuri']=KT_getFullUri();
                $_SESSION['KT_denied_pagelevels'] = array(1);

                If a page sets these variables, then links to a login page, the user will be redirected to the calling page after they're logged in (not the default page defined in the global login settings).

                The magic happens in this function:
                >function Trigger_Login_AddDynamicFields(&$tNG)

                which is found in this file:
                >/includes/tng/triggers/tNG_defTrigg.inc.php

                the switch statement actually has a mistake in it (the if statements are nested incorrectly) that requires the KT_denied_pagelevels variable to be set before the "magic" happens. From the code comments it appears that it's supposed to work with just the KT_denied_pageuri variable set.

                The info=DENIED url parameter just sets the error info box message. It can also say MAXTRIES or ACCOUNT_EXPIRE

                b IN SHORT
                >If you want to be automagically redirected BACK to the page you came from after logging in from a separate linked login page, set the two session variables (as above) on the page with the login link.

                Cheers!
                • 5. Re: How to set KT_REFERRER session variable for login redirect
                  futurewebservices
                  great work, does the job great. <br /> <br />I did something like this in my header file <br /> <br />I use includes too and call the login page by index.php?mod=login <br /> <br /><?php<br />// Check if were logging in and then send back to original page if not on login page<br /><br />if ($_GET['mod'] != "login") {<br />$_SESSION['KT_denied_pageuri']=KT_getFullUri();<br />$_SESSION['KT_denied_pagelevels'] = array(1);  <br />}<br />?>