• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending user back to referrer

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?

You could save last visited URL in a cookie or in the session.

I use a library called History. More information in the following thread: http://ellislab.com/forums/viewthread/58091/. It's really good!

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...

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:

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

And to retrieve the referrer data

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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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