PHP - Writing Database Information To A PHP File?

孤街浪徒 提交于 2019-12-08 13:42:26

Create a script that generates a config file (e.g. config.php) with the database connection variables. Don't forget to set the right file-permissions after you done with a new config file.

Update:

$config .= "<?php\n"; 
$config .= "\$database = '".$_POST['database ']."';\n";
$config .= "\$user= '".$_POST['user']."';\n";
$config .= "\$pass= '".$_POST['pass']."';\n"; 
$config .= "?>\n"; 

file_put_contents("config.php", $config);

You have to create a file dynamically and store the information on this file.

Before this step you have to decide the variables to be used here and the values to be stored according to the user input.

Put it in a file and include it:

<?php
$dbname = 'database';
$dbpassword = 'password';
?>

try like this

<?php 
$fopen = fopen('config.php', 'w'); 
fwrite($fopen, '1'); 
write($fopen, '$dbname = '$_POST['database']';
$dbpassword =               '$_POST['password']';     ');
fclose($fopen); 
 ?> 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!