CodeIgniter Forums

Full Version: Form Re-submission Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hye guys.
Just need a help!!!
When I was using ci3 so I faced an issue when user clicked browser back button, that's show " resubmit the form", so I solved that issue after setting header in ci3. Now I upgrade my site ci3 to ci4 and again I m facing same issue. Can anyone plz convert this code in CI4?


CI 3 code in Controller construct


$this->output->set_header('Last-Modified:' . gmdate('D, d M Y H:i[Image: confused.png]') . 'GMT');
$this->output->set_header('Cache-Control: no-cache, must-revalidate');
$this->output->set_header('Cache-Control: post-check=0, pre-check=0', false);
$this->output->set_header('Pragma: no-cache');

CI 4 code in BaseController

$response->setHeader('Last-Modified',gmdate("D, d M Y H:i[Image: confused.png]").'GMT');
$response->setHeader('Cache-Control', 'no-store');
$response->setHeader('Cache-Control', 'no-cache');
$response->setHeader('Cache-Control', 'must-revalidate');
$response->setHeader('Cache-Control', 'post-check=0');
$response->setHeader('Cache-Control', 'pre-check=0');
$response->setHeader('Pragma','no-cache');
$response->setHeader('Cache-Control', 'no-cache');

In CI 4 it is not working.
Any help will be appreciated.
You could try this and the end of your code/

PHP Code:
// Sends the output to the browser
// This is typically handled by the framework
$response->send(); 
Thanks for you reply..

I have already checked this but not works.
I was facing same issue and didn't find any authentic solution using ci4.
main difference which i saw was in ci3 while setting header there is set-cookie index in header array but in ci4 cookie did not set by setting header.
I hope someone also was facing that one.
I found the solution by using the following code.
Paste the code in Base controller

$response->removeHeader('Cache-Control');


header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");

Firstly remove the all build-in headers than add new ones.