Hi,
one of the problems is that the fourth line of the second script overwrites the session variable as soon as you submit the form because you're not checking if the script has been requested the first time (with the content parameter) or if the form has been submitted (you need to this in the p_dirs.php script, too.
I created both scripts a litte bit to show you one possible way. Form data validation and some other stuff is missing but the basics should be clear.
I changed the form method to post
p_dirs.php:
<?PHP
$arrDirs = array('news' => 'newsFile.txt',
'career' => 'careerFile.txt');
$strBaseDir = '../';
$destFile = '';
if (isset($_GET['content'])) {
if (array_key_exists($_GET['content'], $arrDirs)) {
$destFile = $strBaseDir.$arrDirs[$_GET['content']];
$_SESSION['destFile'] = $destFile;
} else {
echo '<b>Invalid target file selected</b><br>';
exit;
}
} else if (isset($_SESSION['destFile'])) {
$destFile = $_SESSION['destFile'];
}
?>
p_textChange.php:
<?PHP
session_start();
require_once("../p_dirs.php");
$readout = '';
if (empty($destFile) || !file_exists($destFile)) {
echo "<b>! destination file missing !</b>";
exit;
}
if(isset($_POST['eventsField'])) {
$readout = $_POST['NewsField'];
$fp = fopen($destFile, 'w');
// change the code to use stripslashes only if magic_quotes_gpc is enabled ?
$readout = stripslashes($readout);
fputs($fp, $readout);
fclose($fp);
} else if (isset($_POST['clearAll'])) {
$readout = '';
} else {
$readout = file_get_contents($destFile);
}
?>
<form method="post" action="<?PHP echo $_SERVER[PHP_SELF]; ?>">
<textarea name="NewsField" class="forms" cols="45" rows="20"><?PHP echo $readout; ?></textarea>
<p>
<input type="submit" name="eventsField" class="forms" value="SCHREIBEN/ÄNDERN">
<input type="submit" name="clearAll" class="forms" value="EINGABEFELD DELETE">
</p>
</form>
Thomas