Codeigniter Controller return to previous page

This should help http://www.codeigniter.com/user_guide/libraries/user_agent.html

$this->load->library('user_agent');
if ($this->agent->is_referral())
{
    echo $this->agent->referrer();
}

or straight PHP:

redirect($_SERVER['HTTP_REFERER']);

I've found answer on some thread.

In the page that you want to go back to you can do:

$this->session->set_userdata('referred_from', current_url());

Then redirect back to that page

$referred_from = $this->session->userdata('referred_from');
redirect($referred_from, 'refresh');