如何在配置文件中删除/生成

时间:2013-04-13 07:31:27

标签: php html config

我正在尝试创建一个系统,您可以在网页上编辑config.php文件,其中包含文本字段,这是我的网页代码,但是当我通过网页编辑config.php时发生的事情{{ 3}}它取代了“with / that stop the config from working

<?php

// First bring the actual value of the file:
$file = 'config.php';
// Uncomment next line to check if the file exists in the path
// print_r( glob( dirname(__FILE__) . "/*.php"  ) );

$configFile = html_entity_decode( file_get_contents($file) );

// On submit on the changes update the file
if ( isset( $_POST["save_button"] ) && $_POST["config_changes"]){
  # This doesn't work: $changes = $path = str_replace("\"", "'", $_POST["config_changes"]);
  file_put_contents($file, $_POST["config_changes"]);
}
header("Location: " . $_SERVER["SCRIPT_FILENAME"] );
?>

<html>
  <body>
    <!-- HTML form to send the changes to php -->
    <form method="post" action="file.php">
      <textarea name="config_changes"><?php echo $configFile ?></textarea>
      <button name="save_button">Save</button>
    </form>
  </body>
</html>

这是我的config.php

的代码
<?php

$site_title = "Shopname";
$site_name = "Shopname"; 

$mainpage_header = "Welcome";

$mainpage_content = "Buy A Key"; 

$dbhost = "nolooky"; 
$dbuser = "nolooky"; 
$dbpass = "nolooky"; 
$db = "nolooky"; 

$price1 = "2.50"; 
$price1keys = "1"; 

$price2 = "5.00"; 
$price2keys = "2";

$price3 = "7.50";
$price3keys = "3";

$price4 = "10.00";
$price4keys = "4";

$price5 = "12.50";
$price5keys = "5";

$paypal_email = "myemail"; 
$confirm_email = "myemail";
$fulldomain = "mydomain";

?>

2 个答案:

答案 0 :(得分:0)

以下行将转换双引号

$configFile = html_entity_decode(file_get_contents($file));

可以将其更改为

$configFile = html_entity_decode(file_get_contents($file), ENT_NOQUOTES);

答案 1 :(得分:0)

听起来您的服务器上启用了magic_quotes。在写入文件之前尝试放置它,如果它修复了它,你可以保留它,或者理想地禁用魔术引号/升级到更新的php版本。

`

$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process)) {
    foreach ($val as $k => $v) {
        unset($process[$key][$k]);
        if (is_array($v)) {
            $process[$key][stripslashes($k)] = $v;
            $process[] = &$process[$key][stripslashes($k)];
        } else {
            $process[$key][stripslashes($k)] = stripslashes($v);
        }
    }
}
unset($process);

} ?&GT;`