0

I have a basic CMS running, the three main files are cpanel.php, where the user clicks the "edit" button, this then opens pageeditor.php page, where the changes can be made to the document within an iframe and then the user clicks "save", the data gets passed to the saver.php saving script and then back to cpanel.php.

Everything works fine, except for one thing... Whenever I make the changes and save them, they all work fine. The document gets updated. But if I immediately click "edit" again from the same browser and the same computer, the content in iframe is the OLD one. Funnily enough, if I do it from another computer it works flawlessly, so this probably has something to do with the local cache? Can somebody help me with this please, or let me know if it is possible to force an iframe to refresh the content before loading it? Here is the code:

cpanel.php

<?php
session_start();
if (($_SESSION['logged_in']) != "true") {
    header('Location: index.php?ermess=logout');
}
echo '<?xml version="1.0" encoding="UTF-8""?>'
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

    

    <head>
        <link rel="stylesheet" type="text/css" href="cpanel.css" />
        <title>Control Panel</title>
    </head>

    <body>
        <div class="logout"><a href="../redirector.php?logout=yes">Logout</a></div>
        <div class="welcome">
            <h1>Welcome to the Control Panel.</h1>
            <p>This page allows you to edit the <?php
$url = "http://" . $_SERVER['HTTP_HOST'];
echo "<a href='$url'>";
echo "$url</a>";
?> 
                site. </p>

            <p>Please use the section on the left to edit an existing page or create a new one. The section on the right allows you to upload an image so that you can use it on your web pages, or to delete an image if you no longer need it.</p>
        </div>
        <div class="imagem"><p>
            <h1>Manage images:</h1>
            <form action="uploader.php" method="post" enctype="multipart/form-data">
                <label for="file">Choose a file:</label>
                <input type="file" name="file" id="file" /> <br />
                <input type="submit" name="submit" value="Submit" />
            </form></p>

        </div>
        <div class="pagem">
            <h1>Manage pages:</h1>
            <?php
            if ($handle = opendir('../site')) {
                while (false !== ($file = readdir($handle))) {

                    if (strpos($file, ".html") !== false) {

                        echo $file;
                        echo "<a href='pageeditor.php?pagename=$file'><img src='images/edit.png' alt='Edit the page' /><a/><img src='images/delete.png' alt='Delete the page'><br>";
                    }
                }
                closedir($handle);
            }
            ?>

        </div>
      
    </body>

</html>

pageeditor.php

<?php session_start();
if (isset($_SESSION['logged_in'])!=true)
{
header('Location: login.php?ermess=logout');
}
echo "<?xml version='1.0' encoding='UTF-8'?>";

$_SESSION['pagename']=$_GET['pagename'];?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<link rel="stylesheet" type="text/css" href="cpanel.css" />

<head>

	<title>Page editor</title>
		<script language="Javascript" src="editor.js"></script>
	</head>
	<body>
		<form method="POST" action="saver.php">
			<div>
				<input type="button" onclick="Colour('Green')" style="background-color:Green;" />
				<input type="button" onclick="Colour('Red')" style="background-color:Red;" />
				<input type="button" onclick="Colour('Blue')" style="background-color:Blue;" />
				<input type="button" onclick="Colour('Black')" style="background-color:Black;" />
				<input type="button" onclick="Format('bold')" value="B" />
				<input type="button" onclick="Format('italic')" value="I" />
				<input type="button" onclick="Format('Underline')" value="U" />
				<input type="button" onclick="Format('justifycenter')" value="C" />
				<input type="button" onclick="Format('justifyleft')" value="L" />
				<input type="button" onclick="Format('justifyright')" value="R" /><br/>

<?php echo "<iframe id='textbox' name='textbox' style='width:300px; height:150px'; src='../site/{$_SESSION['pagename']}'></iframe><br/>";?>


				<input type="submit" value="Save changes" />
				<input type="hidden" id="text" name="text" />

			</div>
		</form>
	</body>
</html>

saver.php

<?php

session_start();
if (isset($_SESSION['logged_in']) != true) {
    header('Location: index.php?ermess=logout');
}

$myFile = "../site/{$_SESSION['pagename']}";
$fh = fopen($myFile, 'w');
fwrite($fh, stripslashes($_POST['text']));
fclose($fh);
header('Location: cpanel.php?message=saved');
?>

I know this is not a perfect product, so I welcome any design ideas too, but I just want to make it working before I go any further with making it nice and fluffy :) Thanks very much

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Akash Saikia
0

Solved by adding a

<meta http-Equiv="Cache-Control" Content="no-cache">
    <meta http-Equiv="Pragma"    Content="no-cache">
    <meta http-Equiv="Expires"    Content="0">

statement before every page's content... Happy to hear other solutions.

Edited by Lioshenka: n/a

0

Removing caache is definitely a good idea,but even you can try doing this,i am not sure,but it may help you.

Try creating that partictular iframe dynamically in js or jquery.
And if the page is left,the iframe should get deleted,so each time a new iframe is made and it's src is changed dynamically.

I hope it solves the cache problem.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.