Redirect to referer url in codeigniter

This can help:

CI 2+ https://www.codeigniter.com/userguide2/libraries/user_agent.html

CI 3+ http://www.codeigniter.com/userguide3/libraries/user_agent.html

Below solution is for Codeigniter version 3

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

UPDATE: interesting and useful information on how to obtain referrer information with the same user_agent library
https://www.tutorialandexample.com/user-agent-class/


How about just

redirect($_SERVER['HTTP_REFERER']);

Using php's $_SERVER global variable.

This worked for me!