ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Redirect a user to a specific URL after login

March 20, 2012 11:07am

Subscribe [0]
  • #1 / Mar 20, 2012 11:07am

    glenndavisgroup

    436 posts

    Hi Guys,

    I need some help with redirecting users to a specific URL after login. This is how we need this to work. If I’m on our intranet which requires secure login and want to email someone in the office a URL to a particular page. I want to be able to copy and past the URL for this page in an email for example and I email it to a co-worker. I want the co-worker to be able to click on the link in the email where they will get directed to the login screen if not already logged in. Once they login to the intranet, they should automatically get redirected to the link of the page they clicked on from the email. Is this possible? If so, how can I accomplish this and if needed which add-on can I use to do this? Any help is appreciated.

    Thank you,

    Mike

  • #2 / Mar 20, 2012 3:51pm

    glenndavisgroup

    436 posts

    I figured out how to do this. In case anyone else would like to do this. I’m using the free EE extension called Authenticate which allows me to setup a return address after the user logs in successfully (It also has some other cool features).

    I created a template that checks if the visiting user is logged in or not and redirects them to the root page which gets included in all my templates before it displays the page content. This template has the following code in it:

    {if logged_out}
     <?php 
     $strURL = "";
     if(isset($_SERVER['REQUEST_URI']))
      $strURL = "?url=".$_SERVER['REQUEST_URI'];
     ?>
     {redirect="/<?php echo $strURL;?>"}
    {/if}

    The PHP and EE code above will redirect all none logged in users to the root and attach the page you tried to load if any to the end of the URL.

    Now on my login screen I simply use the following PHP and jquery to set the value of the Authenticate hidden html field called “return” to the page I was trying to pull up like so:

    <script>
    <?php
    $return = "/";
    if(isset($_GET['url'])){
      $return = "".$_GET['url'];
      echo "\$jq('#frmLogin').find('input[name=return]').val('$return');\r\n";
    }
    ?>
    </script>

    Now everything works. Not sure if this is the best way to do this but it seems to work perfectly. I hope this helps anyone else looking to add this to their EE site.

    Cheers,

    Mike

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases