Author Topic: Overwriting variables in a file with php  (Read 279 times)

0 Members and 1 Guest are viewing this topic.

Offline Jax2Topic starter

  • Enthusiast
  • Posts: 273
    • View Profile
Overwriting variables in a file with php
« on: March 16, 2010, 01:54:54 AM »
Hello guys, got a question that will hopefully be simple for someone to answer ....

I have a file named db.php that looks like this:

<?php
$db_host
="";
$db_username="";
$db_dbname="";
$db_password="";
$db_prefix="";
?>


Now, what I am trying to do is to create an installation script for something I am working on. The very first part allows the user to configure their database (MySQL) ... (Yes, I am off to a shaky start already :( )

I have the variables stored in $_POST and they all display fine, but I am not sure how to write to the file.

I've read the manual on fopen, and I'm rather lost. I just want to have it add the variables where they go, so it looks more like this when it's done:


$db_host
="localhost";
$db_username="MyName";
$db_dbname="DataBaseName";
$db_password="DBPassword";
$db_prefix="PF_";


Could anyone help me out here and perhaps point me to a good tutorial or something of that nature? Thank you!

Offline Rustywolf

  • Enthusiast
  • Posts: 72
    • View Profile
Re: Overwriting variables in a file with php
« Reply #1 on: March 16, 2010, 02:08:49 AM »
use fopen, fread and fwrite to get values and str_replace $variable="" with $variable="$value"

Offline ry4n0wnz

  • Enthusiast
  • Posts: 307
    • View Profile
Re: Overwriting variables in a file with php
« Reply #2 on: March 16, 2010, 05:44:01 AM »
I recommend directing the data to a page to check if the sql can be connected to through the input connection details, then to post the data yet again to a filewrite system if it works.
function bored() {
$facialExpression = 0;
$movement = "minimum";
echo "I'm Bored";
}