In the page that you want to go back to you can do:
<?php $this->session->set_userdata('referred_from', current_url()); ?>
Then from controller you want to back:
$referred_from = $this->session->userdata('referred_from'); redirect($referred_from, 'refresh');