Imad Posted March 8, 2008 Share Posted March 8, 2008 Hi guys, I'm creating an installer for one of my scripts but I'm having some troubles. In the config file I have this: $host = 'localhost'; $dbuser = ' '; $dbpass = ' '; $db = ' '; From the installer, I want my users to be able to modify the values of the above variables through input boxes, with each variables values in each input box. How can I do this? Kind Regards. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 8, 2008 Share Posted March 8, 2008 reading and writing to file, you may want to look into fopen(), fread(), fwrite(), fclose() Quote Link to comment Share on other sites More sharing options...
Imad Posted March 8, 2008 Author Share Posted March 8, 2008 Thanks for your reply, I'll give it a whirl. Kind Regards. Quote Link to comment Share on other sites More sharing options...
Imad Posted March 8, 2008 Author Share Posted March 8, 2008 fread() doesn't work when I try to list a variables value. Instead it lists the file by size. Any other ideas? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 8, 2008 Share Posted March 8, 2008 try this. It assumes the file is "config.inc.php" <?php $host='localhost'; $dbuser='myusername'; $dbpass='secretstuff'; $db='mydbname'; ?> <?php if (isset($_POST['sub'])) { // update the config file $str = "<?php\n"; foreach ($_POST as $k=>$v) { if ($k != 'sub') // ignore submit button { $str .= "\$$k='$v';\n"; // add line to config file text } } $str .= '?>'; file_put_contents('config.inc.php', $str); exit ('Config file updated'); } include 'config.inc.php'; ?> <form method='post'> Host name <input type="text" name="host" value="<?php echo $host?>"> <br/> DB User <input type="text" name="dbuser" value="<?php echo $dbuser?>"> <br/> Password <input type="text" name="dbpass" value="<?php echo $dbpass?>"> <br/> Database <input type="text" name="db" value="<?php echo $db?>"> <br/> <input type="submit" name="sub" value="Update"> </form> Quote Link to comment Share on other sites More sharing options...
Imad Posted March 8, 2008 Author Share Posted March 8, 2008 Thanks, it worked. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.