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

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.