smugford smugford - 1 year ago 82
PHP Question

Browser Cache Issue On Submitted Form

I don't believe this is a framework issue. In my research it seems to be a browser cache issue but the things I've tried have not worked.

Unfortunately even though I don't want the user to click the back button but obviously there is no way (really) to block the user from clicking the back button.

This is the result of the form upload.

enter image description here

This works fine I get the expected result.

When the user clicks the back button they get the orignal form instead of the image that they just uploaded.

enter image description here
after the user clicks refresh after clicking the back button from the submitted form they get the uploaded image that should show up.

enter image description here

I do have two templates layout.php and layout_wide.php

I have tried this in both templates.

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="pragma" content="no-cache" />

I have tried this custom helper...

function include_stylesheets_versioned()
$response = sfContext::getInstance()->getResponse();
sfConfig::set('symfony.asset.stylesheets_included', true);
$html = '';
foreach ($response->getStylesheets() as $file => $options) {
if ((strpos($file, '?') === false) && (stripos($file, 'http') !== 0) ) {
$file .= '?v='.sfConfig::get('app_resource_version');
$html .= stylesheet_tag($file, $options);
echo $html;
function include_javascripts_versioned()
$response = sfContext::getInstance()->getResponse();
sfConfig::set('symfony.asset.javascripts_included', true);
$html = '';
foreach ($response->getJavascripts() as $file => $options) {
if ((strpos($file, '?') === false) && (stripos($file, 'http') !== 0) ) {
$file .= '?v='.sfConfig::get('app_resource_version');

$html .= javascript_include_tag($file, $options);

echo $html;

I am ready to try putting it in a modal or an iframe to take the back button issue out for this form. But I have another form with a similar issue where putting into a modal isn't an option.

I did see the Post Redirect Get Design Pattern yesterday and think it may be a solution but I am wondering why the meta tags are not working at all.

I realize this may be a duplicate question but I couldn't find a solution that worked.

Has anyone else run into this and can someone please point me to a solution.

The app is sitting on a AWS instance and the Server is NGINX if that has any bearing on it.

Thank you in advance.

Answer Source

I need to redo my layout templates to follow the new standards. They were original created quite some time ago.

This works and gives me a new time result on the back button.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="en" lang="en">
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");

<?php include_javascripts() ?>
<?php include_stylesheets() ?>
<?php include_http_metas() ?>
<?php include_metas() ?>
<?php include_title() ?>
<link rel="shortcut icon" href="/favicon.ico" />
 <?php echo $sf_content ?>
<?php echo time(); ?>

I think the big change is in the DOCTYPE


<!DOCTYPE html>


None of the above worked in symfony 1.4.20

For those few of you that are still using 1.4 I had to put the following into the action to make it work.

    $this->getResponse()->setHttpHeader('Cache-Control', 'no-cache, no-store, must-revalidate, max-age=0, private'); 
    $this->getResponse()->setHttpHeader('Pragma', 'private'); 
    $this->getResponse()->setHttpHeader('Expires', 0); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download