ItSolutionStuff.com

How to Get Previous Page URL in Codeigniter?

By Hardik Savani • November 5, 2023
PHP Codeigniter

Today, i will tech you how to redirect previous page url in codeigniter php. we may sometime require to redirect previous page after login then you can get previous page path by using codeigniter user_agent library, request array or using session.

here, i will show you both example to getting previous page url so, you can simply redirect on that page in codeigniter 3 application.

first we will see user_agent library using referrer() for getting previous page url.

Example 1:

$this->load->library('user_agent');

if ($this->agent->is_referral()){

print_r($this->agent->referrer());

}

Example 2:

print_r($_SERVER['HTTP_REFERER']);

Example 3:

Controller method, using session:

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

Getting in Controller method:

$previous_url = $this->session->userdata('previous_url');

print_r($previous_url);

I hope it can help you....

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Codeigniter Dynamic Highcharts Example

Read Now →

Codeigniter Implement Fullcalendar Example Tutorial

Read Now →

Codeigniter Create Zip File and Download Example

Read Now →

Codeigniter Multiple Database Connection Example

Read Now →

How to implement and use DataTables in CodeIgniter?

Read Now →

Codeigniter Resize Image and Create Thumbnail Example

Read Now →

Codeigniter Drag and Drop Multiple Image Upload Example

Read Now →

Codeigniter Ajax Infinite Scroll Pagination Example

Read Now →

How to Get Last Record in Codeigniter?

Read Now →

How to Get Last Inserted ID in Codeigniter?

Read Now →

Codeigniter Select2 Ajax Autocomplete from Database Example

Read Now →

How to Get Current URL with Query String in Codeigniter?

Read Now →

How to Get Current URL in Codeigniter?

Read Now →

How to Get IP Address in Codeigniter?

Read Now →