Welcome Guest, Not a member yet? Register   Sign In
Redirects
#1

[eluser]Think Floyd[/eluser]
Hi all,

I apologise tremendously if this has been mentioned before, but I struggled to find help through Googling.

Basically I'm generating links and need to append a redirect on the end with the current URL, so that that user can be directed back to the page they are viewing after submission.

In essence, I need to be able to do something like this:

http://www.mycoolwebsite.com/controller/...DIRECT_URL

I don't really want to enable query strings (?redirect=blah) just for this purpose.

Does anyone have any best practices/ideas on how a URL could be stored for redirection? (sessions perhaps...)

Many thanks
TF
#2

[eluser]Cro_Crx[/eluser]
You can do this one of two ways. Either store the redirect uri in the url after the /controller/method of the page your current only eg..

Code:
http://www.mycoolwebsite.com/controller/method/1/redirect/back/to/here

And then just pick it out using the uri helper.

You can use session variables as well, so on the page where you want to save the session variables do something like this.

Code:
$this->session->set_userdata('last_uri', current_url());

Then just retrieve it and use it for the redirect url like:

Code:
$session_id = $this->session->userdata('last_uri');

The second method I use over the first usually. It allows your URI's to stay neat. You just need to make sure that if the last_uri isn't set for whatever reason that the application still functions correctly.
#3

[eluser]Aken[/eluser]
The session information is how I'd do it. Although another method that may help is to encode the URL somehow, so that it is a single large string of random characters (like a session ID you may see on some websites). That way it will just seem like that to your users, and you won't need to parse multiple parameters because of the slashes in the redirect URL.
#4

[eluser]Think Floyd[/eluser]
Thanks chaps, the session method works perfectly. Smile




Theme © iAndrew 2016 - Forum software by © MyBB