Welcome Guest, Not a member yet? Register   Sign In
How get referring URL?
#10

[eluser]brettalton[/eluser]
Sorry for upping an old post, but this is the solution I use:

Say I have a controller and the page (or second segment) determines I'm not logged in. (e.g trying to view '/pages/books' but that is for logged in members only):
Code:
function page()
{
    if ( ! LOGGED_IN)
    {
        redirect('/auth/login/page/books');
    }
}

Then in my auth controller, I read the third and fourth segment and redirect to those after I've completed my login process.

Code:
function login($seg3, $seg4)
{
    //login process
    redirect($seg3.'/'.$seg4);
}

Thus redirecting the user to '/page/books/' after logging in.

To make it automatically redirect when clicking 'login', 'logout', 'register', etc. to return the user to their original page, I build the anchor automatically with uri_string() (requires the URL helper). Since the URL could become '/auth/login/auth/login/page/books' (if someone clicked the link to 'books' a second time, after already being redirected, I remove all instances of '/auth/login' in the '/auth/login' link:
Code:
<li><a href="/auth/login&lt;?php echo str_ireplace('/auth/login', '', uri_string()); ?&gt;">Login</a></li>

Thus, for the 'register' link, it'll look like:
Code:
<li><a href="/auth/register&lt;?php echo str_ireplace('/auth/register', '', uri_string()); ?&gt;">Register</a></li>

People could hack the URI, but it'll just refer them to a non-existant page if they do. If they delete the third and fourth segment so it just says '/auth/login/', then they'll get redirect to '/', which is the home page.

Works for me.


Messages In This Thread
How get referring URL? - by El Forum - 08-25-2007, 12:44 PM
How get referring URL? - by El Forum - 08-25-2007, 08:03 PM
How get referring URL? - by El Forum - 08-25-2007, 10:30 PM
How get referring URL? - by El Forum - 08-26-2007, 11:10 AM
How get referring URL? - by El Forum - 08-26-2007, 02:12 PM
How get referring URL? - by El Forum - 08-06-2008, 10:06 AM
How get referring URL? - by El Forum - 08-06-2008, 10:17 AM
How get referring URL? - by El Forum - 08-06-2008, 11:03 AM
How get referring URL? - by El Forum - 08-06-2008, 11:03 AM
How get referring URL? - by El Forum - 09-17-2010, 10:10 AM
How get referring URL? - by El Forum - 06-02-2012, 10:27 AM
How get referring URL? - by El Forum - 06-02-2012, 01:44 PM
How get referring URL? - by El Forum - 06-02-2012, 02:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB