redirect to previous page? |
[eluser]Arun Joshi[/eluser]
Can I maintain the previous page url in CI? ie, Now am at Code: http://localhost/technoneeds/posts/category/3 I click a link on this page which redirected to page Code: http://localhost/technoneeds/posts/editpost/29 In this page if the user have no essential credential for editing a post, I want to redirect him to the previous page ,ie http://localhost/technoneeds/posts/category/3. Is there any CI method for this?
[eluser]Dam1an[/eluser]
This is not built into the core (AFAIK) but is easy to add yourself There is a library which does that here (but I've never used it, so can't recommend it) I personally just set the uri_string using uri_string() (part of the URI helper) into the userdata. I can then just redirect to that value when I need to
[eluser]Evil Wizard[/eluser]
If you extend the main CI controller then you could store the referer in the session Code: $this->session->set_userdata('refered_from', $_SERVER['HTTP_REFERER']); Code: redirect($this->session->userdata('refered_from');
[eluser]tison[/eluser]
Yes, thank you Dam1an. Your method worked great for redirecting or returning to the previous page, or last page. (think i got all the keywords there for the next searchers). In any case, I added this code to my controllers: Code: $this->session->set_userdata('previous_page', uri_string()); And saved the previous page to my page's form, then after saving redirected users (in my second controller): Code: $previous_page = $this->session->userdata('previous_page'); ** We had to check $previous_page != '' as in the version I'm running, unset_userdata doesn't remove the item, it sets it to empty string ***
[eluser]costicanu[/eluser]
Evil Wizard your idea works. Dam1an that uri_string is very strange when pressing "Submit" button. Strange behaviour, instead of editPage/verify.html (last visited page), it's editPage/edit/img/0.png , so, use $this->session->set_userdata('refered_from', $_SERVER['HTTP_REFERER']);
[eluser]costicanu[/eluser]
I don't care about dates. I had that problem and Evil Wizard had the solution!
[eluser]InsiteFX[/eluser]
Ok, and what happen's $_SERVER['HTTP_REFERER']); returns NULL? 404 PAGE NOT FOUND! Here is the correct way to code it! Code: if (isset($_SERVER['HTTP_REFERER'])) InsiteFX
[eluser]Unknown[/eluser]
Just put this in the controller function Code: redirect($_SERVER['HTTP_REFERER']);
[eluser]35mm[/eluser]
[quote author="stenquist" date="1380487785"]Just put this in the controller function Code: redirect($_SERVER['HTTP_REFERER']); And for users that block or don't have headers set? It would be best to use a cookie/flash session so that any part of your system that needs it can use it - fr example to return to previous page after user logs in etc. |
Welcome Guest, Not a member yet? Register Sign In |