Jump to content

Quick Help editing php from inside php


JonnySnip3r

Recommended Posts

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 :D

Link to comment
https://forums.phpfreaks.com/topic/227148-quick-help-editing-php-from-inside-php/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.