[HELP] fwrite

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

[HELP] fwrite

Post by bla5e »

Code: Select all

<?php      
$config_data = '<?php'."\n\n";
$config_data .= "\n//auto-generated config file for $sitename \n// Do not change anything in this file!\n\n";
$config_data .= '$sitename = \'' . $_POST['sitename'] . '\';' . "\n\n";
$config_data .= '$siteterms = \'' . $_POST['siteterms'] . '\';' . "\n\n";
$config_data .= '$siteauthor = \'' . $_POST['siteauthor'] . '\';' . "\n\n";
$config_data .= '$adminusn = \'' . $_POST['adminusn'] . '\';' . "\n\n";
$config_data .= '$adminpw = \'' . $_POST['adminpw'] . '\';' . "\n\n";
$config_data .= '$host = \'' . $_POST['host'] . '\';' . "\n\n";
$config_data .= '$db = \'' . $_POST['db'] . '\';' . "\n\n";
$config_data .= '$username = \'' . $_POST['username'] . '\';' . "\n\n";
$config_data .= '$password = \'' . $_POST['password'] . '\';' . "\n\n";
$config_data .= '?' . '>';

$data = fopen("config.php", "w");

fwrite($data, stripslashes($HTTP_POST_VARS['config_data']));

fclose($data);

echo "File created";
break;
?>
(There is a form before this page)

It wont write the config.php file, but it reads the $_POST variables..
why wont it work!?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you're trying to access config_data from an array key in HTTP_POST_VARS.

try changing it to this:

Code: Select all

fwrite($data, stripslashes($config_data));
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

Still doesnt read the $config_data variable, any other ideas??
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

do this:
1) try echoing out the $config_data var to make sure you're dealing with the correct stuff
2) make sure you have permissions to write a file in the folder you're working on.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

Burrito wrote:do this:
1) try echoing out the $config_data var to make sure you're dealing with the correct stuff
2) make sure you have permissions to write a file in the folder you're working on.
1) i did any nothing is expressed, but if i echo the $_POST data it does..
2) Ive got CHMOD 777 on both the folder and the config.php file
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

i got it to work. thanks
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

if you don't mind would you share your soultion so that anyone expierencing a similar problem may recieve help
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

dull1554 wrote:if you don't mind would you share your soultion so that anyone expierencing a similar problem may recieve help
didnt chmod the folder :oops:
Post Reply