Jump to content

write variables string to another file


echoCarlos

Recommended Posts

Hi guys, I have a php file called install.php and the user submits there host details, the thing is i also want to write those details to these define functions in includes/config.php with the content

 

define('DB_HOST', 'change1');
define('DB_USER', 'change2');
define('DB_PASS', 'change3');

 

and overwrite change1 with host and user and pass

 

how could this be done

 

thanks

Link to comment
Share on other sites

if you have the 'blank' file saved already, use the file object to read the file into a variable, and use str_replace() to change it.

$filetext = str_replace('change1','localhost',$filetext);

 

assume i have read the file contents of the example you gave, into $filetext, I then ask it to look for 'change1' in that string and replace that with 'localhost', and pass it back to the $filetext. i would then write that variable to the file and save file .

Link to comment
Share on other sites

Thanks for the help but i managed to find something which did the trick on Google will post here incase anyone needs it.

 


<?php



$string = '<?php 

$dbhost = "'. $_POST["dbhost"]. '";

$dbuname = "'. $_POST["dbuname"]. '";

$dbpass = "'. $_POST["dbpass"]. '";

$dbname = "'. $_POST["dbname"]. '";

$prefix = "'. $_POST["prefix"]. '";

$user_prefix = "'. $_POST["user_prefix"]. '";

$dbtype = "'. $_POST["dbtype"]. '";

?>';



$fp = fopen("config.php", "w");

fwrite($fp, $string);

fclose($fp);



?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.