【发布时间】:2013-04-14 01:19:30
【问题描述】:
我已经制作了一个系统,允许您通过网页上的文本字段编辑 config.php 文件但是文本框显示整个文件内容有没有办法我可以限制它只显示一行的一部分这个
$paypal_email = "mypaypalemail@gmail.com";
只显示
mypaypalemail@gmail.com
在文本框中。这是我的代码
<?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);
?>
<?php
$file = 'config.php';
// print_r( glob( dirname(__FILE__) . "/*.php" ) );
$configFile = html_entity_decode(file_get_contents($file), ENT_NOQUOTES);
if ( isset( $_POST["save_button"] ) && $_POST["config_changes"]){
$changes = $path = str_replace("\"", "", $_POST["config_changes"]);
file_put_contents($file, $_POST["config_changes"]);
}
?>
<html>
<body>
<center>
<b>
<font face="arial" size="3" color="#000000">
Welcome edit your Options here
<br>
<form method="post" action="controlpanel.php">
<textarea name="config_changes" rows="30" cols="50"><?php echo $configFile ?></textarea>
<br>
<button name="save_button">Save</button>
</form>
</body>
</html>
【问题讨论】:
-
我认为这是不安全的编程,但您可能只需要使用正则表达式和 PHP preg_match 函数
-
如果您打算执行 config.php,那真的非常不安全,因为注入任意代码是微不足道的。我建议改用 JSON 编码文件或类似文件,并清理允许从白名单中设置哪些键。
标签: php html file config textfield