redirecting to previous page

How do you all go about redirecting to a previous page in CI?

My situation: I have a message board like system with links to private message posters. When clicked, the private message page loads and they submit it... now I want to send the user back to the board page he came from.

Would you guys just use HTTP_REFERER? is there a better way to do this in CI?

edit: sorry, I should have posted this in Code and Application Development

I have the same question and would appreciate it if someone tell me how to redirect to a previous page after submitting a form for example!

I would not use HTTP_REFERER because it's not reliable.

As usual there are multiple ways to do this and it depends how generic you want it to be.

For forms, it's not too unusual to pass return urls as a query parameter or a hidden form field.

If you need to be able to reliably track 'every' page, because your link is in the header or something you would need to store it more generically.

For that you could set a session variable on every page visit, but that would potentially negate usage of the powerful caching feature in CI and could thus be expensive.

Another option is to store the return page in a Cookie. You can do that early in the command chain, e.g. your index.php or hook. Or you can do it in JavaScript and thus less expensive - but limited to browsers with Javascript enabled. Which is pretty much a given these days.

Hope this helps,

You're probably allready using the session library. If you're not using caching, I'd store it in a piece of flashdata... Nice and easy.

However, if it's just for forms, I'd send a referrer URL with a hidden input.

i will try using the cookie method...the HTTP_REFERER doesn't work at all with me, thank you for your reply

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.