this might be a simple fix, but it certainly doesn't seem to be.

I have built a EE-based web application, and as is part and parcel with web applications, users are required to log into the system.

With our application, users are often sent links like profile links, sort of like a social network works. However, at the moment, when users click on the links, they are required to login, and then they are brought to a generic template after logging in. I've tried using this http://devot-ee.com/add-ons/preevious but the value is coming up as blank regardless of how many times I try to use it.

Any ideas? Realistically, this is a massive deterrent for our users. If they are sent a link to a page, they need to log into the system, and then go back and click on the link in an email or via whatever other medium they were sent the link.

Any help or input would be massively appreciated. By the way, we are using standard access restrictions on this web app, which are set in the Template Manager. So if I try to go to domain.com/contacts, it will redirect me to domain.com/login and then once I login it will bring me to domain.com/home because that is our index page.

Cheers in advance, Conor

  • When they click on the link, are they be taken directly to the 'link' url, with a message on page that they need to login, or are they being redirected to a login page immediately? Commented Apr 11, 2013 at 21:22
  • So when the user clicks on the link or tries to load a url into the browser, if they are not logged in, then it will attempt to go to the specified URL, their access will be restricted and they will be forced to go to the login page. Commented Apr 11, 2013 at 21:39

2 Answers 2


There are a few ways to do this, I find the easiest to be, to make the login page, available everywhere.

For example, we frequently have the login available from the Navigation Bar or one of those TopNav bars, say like Twitter. Generally, in either case, we use either CSS hide/display or an overlay window to display the login option. And have the login return them to the same page.

We've done this using Solspace's User, Authenticate, Zoo Visitor, and SafeCracker Registration. I'm certain any of the other add-ons for membership or registration will also allow you to do it as well.

Generally, speaking, if your login is available from ANYWHERE, then you don't really have to worry about re-directing the user back to where they came from. I like using FancyBox or another overlay script to provide the fields to enter in username and password, log them in, then drop them back onto the page.

Even without an add-on, you can set-up pages that require login access to display the login, when the user isn't logged in.

Using the built-in Member Login Form, see Login Form Tag. You can set-up something like:

 {exp:member:login_form return="{site_url}/{segment_1}/{segment_2}/{segment_3}"}

          <input type="text" name="username" value="" maxlength="32" size="25">
          <input type="password" name="password" value="" maxlength="32" size="25">
     {if auto_login}
          <p><input type="checkbox" name="auto_login" value="1"> Auto-login on future visits</p>

     <p><input type="checkbox" name="anon" value="1" checked="checked"> Show my name in the online users list</p>
     <p><input type="submit" name="submit" value="Submit"></p>
     <p><a href="{path='member/forgot_password'}">Forgot your password?</a></p>


This form combined with the page logic like

{if logged in}

Should work.

  • This is definitely a very good and plausible solution, though it's not exactly what we are able to use as it takes a lot of reworking on each template and we have tonnes of content on the app. We found a great solution though which I'll post in a sec as an answer. Thanks for your input though! Commented Apr 12, 2013 at 10:10

Found a great solution this morning. We are now using stash to set values before pages are redirected and then to get the value on the login template. It is fairly similar to nonprofit_tech's suggestion above, except this is all handled on a single page which is being set for all our redirects. So if a user has no access to a page, they are sent to the site's index. Then if they are logged out, set a stash variable, and redirect them to the login template.

{if logged_out}
    {exp:stash:set name="preLoginUrl" scope="user" save="yes"}{site_url}{segment_1}{if segment_2}/{segment_2}{/if}{if segment_3}/{segment_3}{/if}{/exp:stash:set}
    ...perform a bunch of routing here...

Then on the login template (using a zoo visitor login form):

{exp:zoo_visitor:login_form error_handling="inline"}
                    <input type="hidden" name="RET" value="{exp:stash:get name="preLoginUrl" process="inline"}" />

                    {if "{error:login}" != ""}
                    <div class="content dashed-bottom error-holder">
                        <span class="tag danger">{error:login}</span>
                    <div class="fieldset-holder cf">
                            <input type="text" name="username">
                            <input name="password" type="password">
                        <fieldset class="inline grid-33">
                            <label for="loginButton" class="button block primary"><i class="icon-key"></i><span>Sign In</span>
                                <input id="loginButton" class="hide-submit" type="submit" value="submit">
                        <fieldset class="inline grid-66 text align-right">
                            <div><a href="{site_url}login/reset/" class="link">Forgot your password?</a></div>

We tried everything from cookies to using php referrer headers and nothing worked apart from stash.

Hopefully this helps someone else out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.