How to get previous page url in codeigniter

18,920

Solution 1

try this:

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

In this way you load user_agent library, check if there is a referral url and then store It into a variable to use It after

Solution 2

It may be helpful

$url= $_SERVER['HTTP_REFERER'];
Share:
18,920
Nighina t t
Author by

Nighina t t

Updated on July 06, 2022

Comments

  • Nighina t t
    Nighina t t almost 2 years

    I need privously visited page url in a variable and to find it inside a controller. is there any way to find it?please help me.By using following code redirect($this->agent->referrer());

    i can redirected to the previous page .but I need this inside a variable to check.

    • M. Eriksson
      M. Eriksson almost 7 years
      Have you simply tried: $someVariable = $this->agent->referrer(); ?
  • Sohan Arafat
    Sohan Arafat over 2 years
    Would you please tell me for CI4?
  • Admin
    Admin over 2 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.