1

First off, I'm sorry if this shows no code which is not what Stack Overflow is about..But I have no clue where to go on this. I have a basic CMS I made, and I am trying to distribute it. I want to make it so that upon going to /cms/install for example, they set the database info, and different info to integrate into the CMS. Now my issue is, what would be the best method to allow the user to store that database info? A cookie seems to not be the right way..Could I store database info inside of a database? Not too sure where to go on this. More or less. What is the best way to temporarily store the database information the user gave before arrival of the full CMS.

<?php 
$fopen = fopen('config.php', 'w'); 
fwrite($fopen, '1'); 
write($fopen, '<?php $dbname = '$_POST['database']'; $dbpassword = '$_POST['password']';     ?>'); fclose($fopen); 
?> 

Would this work?

4 Answers 4

2

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Using fwrite? Or is there another more easy way of achieving that?
$config .= "<?php\n"; $config .= "\$database = 'DB';\n"; $config .= "\$user= 'user';\n"; $config .= "\$pas= 'pass';\n"; $config .= "?>\n"; file_put_contents("config.php", $config);
1

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.

Comments

1

Put it in a file and include it:

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

2 Comments

<?php $fopen = fopen('config.php', 'w'); fwrite($fopen, '1'); write($fopen, '<?php $dbname = '$_GET['database']'; $dbpassword = '$_GET['password']'; ?>'); fclose($fopen); ?> Would this work?
<?php $fopen = fopen('config.php', 'w'); fwrite($fopen, '<?php $dbname = '$_GET['database']'; $dbpassword = '$_GET['password']'; ?>'); fclose($fopen); ?> should work. why do you have fwrite($fopen, '1'); ?
0

try like this

<?php 
$fopen = fopen('config.php', 'w'); 
fwrite($fopen, '1'); 
write($fopen, '$dbname = '$_POST['database']';
$dbpassword =               '$_POST['password']';     ');
fclose($fopen); 
 ?> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.