I’m trying to create a very simple way to update content on a website using a php script to edit the php pages themselves. All of the pages, index.php, about.php etc. only contain: a variable
$body
which is the text of the page and an
include();
call which loads the layout of the page.
I have this which can edit the full php page:
$mydir = ".";
$file = "index.php";
$curdir=dir($mydir);
$writefile = $_REQUEST['writefile'];
$text = $_REQUEST['text'];
if($writefile)
{
$fd=fopen($mydir."/".$file, "w");
fwrite($fd, stripslashes($text));
fclose($fd);
echo "<font color=red><strong>File updated</strong></font>";
echo "<meta http-equiv=\"Refresh\" content=\"3; URL=$PHP_SELF\">";
}
elseif($file)
{
$fp=fopen($mydir."/".$file, "r"); // $mydir$myfile
while(!feof($fp)) {
//$content .= fgets($body);
$content .= fgets($fp, 4096);
}
fclose($fp);
echo "<FORM ACTION='$PHP_SELF' METHOD='post'>";
echo "<input type=hidden name=writefile value=true>";
echo "<TITLE>Editor</TITLE>";
echo "<TEXTAREA ROWS='20' COLS='80' NAME='text'>";
echo "$content";
echo "</TEXTAREA><BR>";
echo "<input type='submit' value='Update'><br></form>";
}
It works great but how can i make it so it only loads the value of
$body
into
$content
instead of the whole php page? Since i’m only needing to edit the text, i only want to load that into the text form field. Thanks!