如何使用设置文件编辑配置 PHP 文件


how to edit config php file with setting file

我有一个小脚本,我想让用户编辑"config.php"文件的可能性,脚本在(设置.php)页面中。

例如,它们是"config.php中的一些代码

$title = 'myblog';
$email = 'info@google.com';
$desc = 'Something';

想要一个 "HTML"页面 ,以获取我所说的内容的价值。(用户输入值,该值应在脚本的其他部分中使用)

如果你想要类似的东西,用户可以更改标题,如果有多个用户意味着如果一个用户更改配置.php标题将更改为其余的。因此,最好使用数据库。

如果只有一个用户,则可以使用文件来存储信息。

请解释更多您想做什么,一个用户还是多个用户?

你最好这样做:在设置.php文件中:

<form action="settings2.php" method="POST">
Title:<input type="test" name="title"><br>
Email:<input type="test" name="email"><br>
Desc:<input type="test" name="desc"><br>
<input type="submit">

和设置2.php:

<?php
$title = $_POST['title'];
$email = $_POST['email'];
$desc = $_POST['desc'];
    $content= '<?php
    $title = "'.$title.'";
    $email = "'.$email.'";
    $desc = "'.$desc.'";
    ?>';
    $file = "config.php";
    $fh = fopen($file, 'w') or die("can't open file");
    fwrite($fh, $content);
fclose($fh);
?>

这 2 个页面将放入配置.php表单提交的值,例如:

<?php
        $title = "PHP";
        $email = "email@email.com";
        $desc = "something";
        ?>