Welcome Guest, Not a member yet? Register   Sign In
Sending user back to referrer
#1

[eluser]Nial[/eluser]
I wanted to ask how people here handle this in CI/PHP: Basically, I have an AJAX powered function on my website. When a user clicks a link, Javascript is executed and an AJAX request is sent off. That's fine. However, in the interest of making my Javascript/AJAX degradable, the link will default to a standard URL when Javascript is not enabled.

The problem I'm having is figuring out how to return the user to the page that they were on before they clicked the link. In a nutshell:

User clicks link -> controller method is called -> database is updated -> return user to the page where they clicked the link.

The obvious solution would be to take the entire url and append it to the link URL, but I'm not sure how I'd parse the URL on the other side, given CI's URL structure.

Any suggestions?
#2

[eluser]JoostV[/eluser]
You could save last visited URL in a cookie or in the session.
#3

[eluser]erik.brannstrom[/eluser]
I use a library called History. More information in the following thread: http://ellislab.com/forums/viewthread/58091/. It's really good!
#4

[eluser]Bramme[/eluser]
You could simply put $this->session->set_flashdata('referrer', $this->uri->uri_strin()) in your construct and then use redirect($this->session->flashdata('referrer') in the method you need to redirect to...
#5

[eluser]rdjs[/eluser]
There were a couple of small typos in the code above. Nothing major but thought I would clarify to save confusion. Also current_url() was added in version 1.7 and would work nicely here:

To set the referrer in the flashdata:

Code:
$this->session->set_flashdata('referrer', current_url());

And to retrieve the referrer data

Code:
redirect($this->session->flashdata('referrer'), 'refresh');




Theme © iAndrew 2016 - Forum software by © MyBB