简体   繁体   中英

how to edit config php file with setting file

i have a little script and i want to give possibility to the user to edit the " config.php " file , with the script in the ( setting.php ) page .

For Example , they are some of codes in "config.php"

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

i want to have a " HTML " page , to get the value of the things that i said. (the user enter the value and the value should be used in other parts of script)

if you want something like the user can change the title, if there are more than one user means if one changes config.php the title will be changed for the rest. so, it's better to use a databases.

if it's only one user, you can use a file to store the information in.

please, explain more what you want to do, one user or more than one ?

You should better do this: In the settings.php file:

<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">

And settings2.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);
?>

These 2 pages will put in config.php the values submited by the form, for example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM