4

I am loading a form in an overlay. The overlay has a separate controller and action to the page that invokes the overlay.

On form submit, if successful, I simply want to reload the referring page that the overlay was loaded from. I can get the referring page to load, but it places the content inside the overlay.

header("Location: www.example.com", true, 302);

does not work.

Using the URL helper like this:

$url = $_SERVER['HTTP_REFERER'];
redirect($url);

Also does not work. Every time it loads in the overlay. I am sad because of it.

Evernoob
  • 5,551
  • 8
  • 37
  • 49
  • What are you using for an overlay? If you're using a new window, then you will have trouble trying to refresh the main page. You should be using a fancybox or lightbox or something. – Catfish Oct 12 '12 at 16:33
  • A bit vague. This refer page when called seperately, the overlay is there or not? – itachi Oct 12 '12 at 16:36
  • Btw avoid using `HTTP_REFERER`. It isn't consistent in all browsers and your codes may break. – itachi Oct 12 '12 at 16:39
  • How is the overlay generated? – raidenace Oct 12 '12 at 16:48

10 Answers10

11

You can use this code to refresh in codeigniter:

redirect($_SERVER['REQUEST_URI'], 'refresh'); 

it should work!

Philip G
  • 4,098
  • 2
  • 22
  • 41
Deepti Gehlot
  • 617
  • 7
  • 8
  • It works, but what if I want to go on a particular function with a flash message just with a refresh. It's confusing here. My problem is [link](https://stackoverflow.com/a/55370364/4000266) . @jasmeen , Philip G and Deepti – heySushil Mar 27 '19 at 05:41
3

This one is more simple

redirect($this->uri->uri_string());

Jasmeen
  • 876
  • 9
  • 16
2

Unfortunately, using header to refresh/redirect will only reflect the changes in the container that is displaying the PHP page.

To refresh the parent page (i.e. the page that is displaying the overlay itself), you will need to do it on the client-side using Javascript. These questions should help you get on the right path:

Community
  • 1
  • 1
Aamir
  • 5,324
  • 2
  • 30
  • 47
1

You can use this code to refresh in codeigniter:

redirect($_SERVER['REQUEST_URI'], 'refresh'); 

Hope this helps.

nKn
  • 13,691
  • 9
  • 45
  • 62
0

You do not have to supply additional two arguments for header. Just use this pattern:

header('Location: www.somewhere.com');

Also, check out this article about a similar matter:

Redirect with CodeIgniter

Community
  • 1
  • 1
0
redirect(site_url(strtolower(__CLASS__)));
maqs
  • 414
  • 4
  • 5
0

It's just

redirect('/some_url', 'refresh');
0

First load under constructor method like as:

function __construct()
  {
    parent::__construct();
$this->load->library('user_agent');
}  

After inserting or update add this method it will work fine.

redirect($this->agent->referrer());
Md.Jewel Mia
  • 3,345
  • 3
  • 19
  • 24
0

I some cases you may need

redirect($_SERVER['HTTP_REFERER']);
Denis Bahlei
  • 33
  • 1
  • 6
-1

This one is more simple for everone :) location.reload()