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