I'm making a website where users select one of the four options - A, B, C, or D (for simplicity) and press a button to be redirected to a different page (page 2) that uses the selection to display one of the four images at the top.

The selection is stored in a text file using PHP.

Page 2 will read the text file and display the picture based on the value read.

The problem is if the user had previously chosen option A and then presses the back button and chooses option C, the first time Page 2 loads, it will still display the picture for option A. Only after refreshing the page once it will load the correct picture for option C.

I tried to prevent IE from caching the page.. but it was no use.

    <meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">

Note: The website only has to work in IE so no need to make it compatible with other browsers...

Anyone know what am I doing wrong here? Or how to prevent the browser from remembering the previous information?

Recommended Answers

All 11 Replies

Did you inspect the header to make sure you implemented the code properly. There are quite a bit of online sites that let you see the results of the header. Check that, just to rule it out as an issue.

Did you inspect the header to make sure you implemented the code properly. There are quite a bit of online sites that let you see the results of the header. Check that, just to rule it out as an issue.

Hmm, the problem is I'm not running this on a publicly accessible server. It will be run locally with a USB web server.

You can also download a tool called Fiddler. I am not an expert with it, but have used it to diagnose issues.

http://www.fiddler2.com/fiddler2/

I set timeouts in .htaccess to 5secs for anything that needs it, is the usb server a wamp/lamp system?

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 5 seconds" 
ExpiresByType image/gif "access plus 5 seconds" 
ExpiresByType image/jpg "access plus 5 seconds" 
ExpiresByType image/png "access plus 5 seconds"  
ExpiresByType application/x-javascript "access plus 5 seconds" 
ExpiresByType text/css "access plus 5 seconds" 
ExpiresByType text/javascript "access plus 5 seconds" 
ExpiresByType image/x-icon "access plus 5 seconds" 
</IfModule>

It's WAMP system. http://www.usbwebserver.net/en/index.php

I also don't have a .htaccess file that I can edit (at least not that I can see)! The USB server has a total of three .htaccess files & they're all for PHPmyadmin...

create a .htaccess file in the html_root (exact location depends on your config, wherever your index.php site root is) folder on the thumb drive,
may be all thats required,
(sometimes -not very often- things work easy),
there is minimal documentation on the site, but it appears that ANYTHING, can go in the thumbserver's html root . My AMP test stack is on my server, but I can see myself grabbing a copy of this thing, just to nhave it

You should have the proper tool for this...Try to fine with your own..

playing with the USBWebserver, .htaccess works if dropped in F:\USBWebserver v8.5\8.5\root

liking it, very few things WORK straight out of the box, this does

I did that, but it's still displaying older version....
.
.
.

I'm not sure if it's the cache that's the problem or my code... :S

What I'm doing is the following:

I have a form.php file that takes in user input (checkboxes and text input).

Whenever the page is being "unloaded" (javascript), the page will submit the form by sending the info to process_script.php. That script will write the info in text files.

After writting, it will redirect the user to the final.php which will pull the info from the text files and display the page. (include() function of PHP)

.
.
.
.

Does any of that seem to be the problem?

if you think it is the code, post the code, there might just be an even simpler fix

Data Input method: there are more like these but this is the general idea...

<input type="radio" class="check" name="gen_company_name" value="other" <?php $data = file_get_contents("http://localhost:8080/core/data/form_generation/gen_company_name.txt"); if ($data == "other") echo "checked"; ?> />Blank<br/>

then to send the data to the script that saves:

<script type="text/javascript">    
        window.onbeforeunload = confirmBrowseAway;

        function confirmBrowseAway()
        {
            document.forms["gen_form"].submit();
        }

        window.onload = function()
        {
            document.forms[0][0].focus();
        }
    </script>

Then to save the inputted data:

<?php
$sfiles[1] = "gen_signature_third_line_feature.txt";                $sinput_name[1] = "gen_signature_third_line_feature";

    for ($si = 0; $si <= 1; $si++)
    {
        if ($_POST[$sinput_name[$si]] == "yes")
        {
            $data = $_POST[$sinput_name[$si]];
            $file = fopen ($directory.$sfiles[$si], "w");
            fwrite ($file, $data);
            fclose($file);
        }
        else
        {
            $data = "no";
            $file = fopen ($directory.$sfiles[$si], "w");
            fwrite ($file, $data);
            fclose($file);
        }
    }
?>

& finally, to retrieve the data:

<p class="RE">RE:</p>
<p class="subject">
    <?php include($serverdir."edited_gen_re_line1.txt"); ?><br/>
    <?php include($serverdir."edited_gen_re_line2.txt"); ?><br/>
    <?php include($serverdir."edited_gen_re_line3.txt"); ?><br/>
</p>

<br/>

<?php include($serverdir."edited_gen_body.txt"); ?><br/>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.