PHP Writing with fopen
Posted: Fri Nov 04, 2005 2:58 pm
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:
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:
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.
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 areaCode: 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";
}
?>For example: Currently it says $dbuser = root but when it writes to the file it only writes = root
Thanks in advance.