The code is finally working, and I thought I'd post it here for anyone interested:
index.php:
PHP Code:
<?php
include('inc.php');
include('layout.php');
?>
<textarea name="about" readonly><?=$about?></textarea><br />
<a href="edit.php?edit_file=about">Edit</a>
<br /><br />
<textarea name="services" readonly><?=$services?></textarea><br />
<a href="edit.php?edit_file=services">Edit</a>
<br /><br />
<textarea name="links" readonly><?=$links?></textarea><br />
<a href="edit.php?edit_file=links">Edit</a>
inc.php:
PHP Code:
<?php
$about = <<<ABOUT101291
about content
ABOUT101291;
$services = <<<SERVICES101291
services content
SERVICES101291;
$links = <<<LINKS101291
links content
LINKS101291;
?>
edit.php:
PHP Code:
<?php
include('inc.php');
include('layout.php');
$array = array('about','services','links');
if(@$_GET['edit_file']){
$edit_file = $_GET['edit_file'];
if(in_array($edit_file,$array)){ ?>
<form method="post" action="confirm.php?edit_file=<?=$edit_file?>">
<textarea name="<?=$edit_file?>"><?=$$edit_file?></textarea><br />
<input type="hidden" name="auth" value="yes" />
<input type="submit" value="Submit" />
</form>
<?php }
else { echo '<p>The file chosen to edit does not exist.</p>';}
}
else { echo '<p>There is no file to edit.</p>';}
?>
write.php:
PHP Code:
<?php
include('inc.php');
echo '<html>
<head>
<title>CMS Example</title>'."\n\n";
$php_file = @file_get_contents('inc.php');
$success = 'http://www.flamehtmlstudios.com/clients/cms/result.php?result=yes';
$fail = 'http://www.flamehtmlstudios.com/clients/cms/result.php?result=no';
$fail2 = 'http://www.flamehtmlstudios.com/clients/cms/result.php?result=no2';
if(@$_GET['edit_file']){
$edit_file = $_GET['edit_file'];
if(@$_POST[$edit_file]){
$page = $_POST[$edit_file];
$pageu = strtoupper($edit_file);
$newcontent = '$'.$edit_file.' = <<<'.$pageu.'101291'."\n".$page."\n".$pageu.'101291;';
list($a,$b) = explode('$'.$edit_file,$php_file,2);
list($b,$c) = explode($pageu."101291;",$b,2);
$php_final = $a."\n\n".$newcontent."\n\n".$c;
$file = 'inc.php';
$file = @fopen($file,'w+');
@fwrite($file,$php_final);
@fclose($file);
echo '<meta http-equiv="refresh" content="0;url='.$success.'">';}
else {?> <meta http-equiv="refresh" content="0;url=<?=$fail?>"> <?php }
}
else { ?> <meta http-equiv="refresh" content="0;url=<?=$fail2?>"> <?php }
echo "\n\n".'</head>
<body>
</body>
</html>';
?>
confirm.php:
PHP Code:
<?php
include('inc.php');
include('layout.php');
if(@$_GET['edit_file']){
$edit_file = $_GET['edit_file'];
if($_POST['auth'] == 'yes'){
$page = $_POST[$edit_file]; ?>
<form method="post" action="write.php?edit_file=<?=$edit_file?>">
<textarea name="<?=$edit_file?>" readonly><?=$page?></textarea><br />
<input type="button" value="Edit" />
<input type="submit" value="Submit" />
</form>
<?php }
else { echo'<p>Please go <a href="edit.php?edit_file='.$edit_file.'">back</a> and fill in the textbox.</p>';}
}
else { echo'<p>There is no file to edit.</p>';}
?>
result.php:
PHP Code:
<?php
include('layout.php');
$error = '<p>There has been an error in trying to edit the page.</p>';
if($_GET['result']){
$result = $_GET['result'];
if($result == 'yes'){
echo '<p>The page has been edited successfully.</p>';}
else if ($result == 'no' || $result == 'no2'){
echo $error;}
else{echo $error;} }
else{echo $error;}
?>
then layout.php just includes some styling.
Bookmarks