Reputation: 1279
Advise me what to do.
I have a file connect.php
, which includes the file config.php
.
I want to make the CMS installer.
Install.php
- User will add a mysql (server login pass dbname) data, and the it will be saved to a file Config.php. How to make it?
Or offer an alternative solution.
Upvotes: 0
Views: 1055
Reputation: 3370
How about after taking mysql credentials and verifying connection, you generate code for config.php by using php's file function in Install.php. Logic of generating of code for config.php will depend on you use config.php.
Here is the sample code, let say config.php is should look like this.
<?php
$config['host'] = "localhost";
$config['user'] = "root";
$config['password'] = "password";
?>
Php code for generating above code will be like.
<?php
$codeStr =<<<CODE <?php
\$config['host'] = "$host";
\$config['user'] = "$username";
\$config['password'] = "$password";
file_put_contents('config.php',$codeStr);
CODE;
?>
Upvotes: 1
Reputation: 145482
How about just writing the file?
file_put_contents("config.php", trim(<<<CONFIG
<?php
\$config["server"] = '$_FORM[server]';
\$config["dbname"] = '$_FORM[dbname]';
...
?>
CONFIG
));
Note that the $_FORM data fields should be escaped (addslashes) prior saving.
Upvotes: 2