Page 1 of 1

PHP Writing with fopen

Posted: Fri Nov 04, 2005 2:58 pm
by waradmin
im working on an automated blog system (like xanga) where users register, and it creates a directory, mysql database, and then copies the files to their directory for their blog. The blog software was written by me, and has a required config.php file that needs to be setup for each persons blog, and it goes in their directory.

So here is an example of what needs to be in the config file:

Code: Select all

#Edit this area to set your admin username and password

$adminuser  = "admin"; #administrator username
$adminpass  = "admin"; #administrator password
$adminknown = "Steve"; #Who the administrator is known as (aka name)

//End of Admin edit area

# Edit this area to set the title of your blog, your email, etc

$title      = "Simpleblog"; #The title of your blog appears in Title Bar for web browser
$blogname   = "steve's blog"; #Name of blog as you want to appear in the page header
$email      = "admin@open-server.org"; #Your email address
$name       = "steve"; #Your name or nick name
$perpage    = "50000"; #Number of entrys for the homepage
$absolute   = "http://www.open-server.org/"; #absolute location of blog

//End general information area
Ok, so the user will fill out a registration form for each one of those variables. Now i need to write that information into a blank config.php file so it looks like the above. The problem is that when i use fopen with the following code:

Code: Select all

<?php
$filename = 'config2.php';
$somecontent = "$dbuser = \"root\"; $dbserver	= \"localhost\";";

if (is_writable($filename)) {

   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
   
   echo "Success, wrote ($somecontent) to file ($filename)";
   
   fclose($handle);

} else {
   echo "The file $filename is not writable";
}
?>
It doesnt write the $ variables. So it only places the = sign and after into the file. How do i get the fopen function to write the whole variable and not just what is after the variable.

For example: Currently it says $dbuser = root but when it writes to the file it only writes = root

Thanks in advance.

Posted: Fri Nov 04, 2005 5:23 pm
by Luke
You're supposed to use single quotes... let me tinker with it for a minute I'll see if I can fix it.

Posted: Fri Nov 04, 2005 5:25 pm
by Luke
try this:

Code: Select all

$somecontent ='$dbuser = "root"; $dbserver    = "localhost";';

Posted: Fri Nov 04, 2005 5:54 pm
by waradmin
That worked thank you.

Next roadblock ive reached is that the user enters a desired username in the signup form. A directory is created with that username, was well as a database. The username is set as $name

So how would i get the config file to set the dbname field (defines the name of the database) to echo the $name that the user entered on their form. I cant seem to get the value of $name to display in the file, just the "$name"

So how would i get the value of $name to display and not just $name?

Thanks.

Posted: Fri Nov 04, 2005 6:29 pm
by Luke
post the code, but probably something like this...

Code: Select all

$somecontent ='$dbuser = "'.$entryone.'"; $dbserver    = "'.$entrytwo.'";';

Posted: Sat Nov 05, 2005 2:51 pm
by waradmin
Thanks for the help that worked perfectly.

I have a beta up in action if anyone wants to try out my blog service: http://blog.open-server.org/

Give feedback if you want. I could use it. Thanks.

Posted: Mon Nov 07, 2005 11:08 pm
by egmax
e.g.

$msg = "\$v1=0; \$v2=1;";

:roll: