JonnySnip3r Posted February 9, 2011 Share Posted February 9, 2011 Hey guys im fairly good with php dont do much struggling apart from now. I decided to make an app that helps the user install itself by checking certain files are writable if there is an installation directory etc etc. But i have come to the point where i want the user to change the username/passwords to access his/her database. i have them pre-defined like so: define('DB_USER','myUsername'); these are stored in includes/config.inc.php I know how to grab data from a user submitted form wither by post/get how would i go about changing these values depending on what the user inputs. So say i capture someones db username like so. $username = $_POST['db_username']; how would i change what ever is stored in the $username variable to replace whats in the define? Thanks guys hope this makes sense Link to comment https://forums.phpfreaks.com/topic/227148-quick-help-editing-php-from-inside-php/ Share on other sites More sharing options...
ChemicalBliss Posted February 9, 2011 Share Posted February 9, 2011 Either; A) Use a config template inside the install file - so the config is created and certain "blanks" are filled in. B) Have a config file already made with specific "replacement strings" that you can use to replace with str_replace(); Like define('DB_USER','%DB_USER_REPLACEMENT_STRING%'); // get config file (fopen()/fread() or file()) - save to $config_data $config_data = str_replace("%DB_USER_REPLACEMENT_STRING%", $db_user_from_install, $config_data) // Delete or "truncate" the config file // then fwrite the config data and close. Voila hope this helps Link to comment https://forums.phpfreaks.com/topic/227148-quick-help-editing-php-from-inside-php/#findComment-1171920 Share on other sites More sharing options...
JonnySnip3r Posted February 11, 2011 Author Share Posted February 11, 2011 Thanks very much helped loooaddss Link to comment https://forums.phpfreaks.com/topic/227148-quick-help-editing-php-from-inside-php/#findComment-1172843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.