FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

error in my safe command

 


golles
I use the following command to save some configuration:

Code:
$file = fopen("config.php", "r+") or die("<p class=\"red\">Fout met openen van het bestand!</p>");
$file_out = fwrite($file, "<?php\n$title = \"{$_POST['title']}\";\n$banner = \"{$_POST['banner']}\";\n$backgroundimg = \"{$_POST['backgroundimg']}\";\n?>") or die("<p class=\"red\">Fout met schrijven naar config.php!<br/>Kijk a.u.b. of de CHmod goed is ingesteld!</p>");
fclose($file);


then config.php should look like something like this:
Code:
<?php
$title = "Bier drinken doe je samen";
$banner = "";
$backgroundimg = "images/heineken7_1024x768.jpg";
?>


but it does looks like this:
Code:
<?php
 = "Bier drinken doe je samen";
 = "";
 = "images/heineken7_1024x768.jpg";
?>es/heineken7_1024x768.jpg";
?>


can anyone tell me what's the error and maybe fix it Embarassed ?
thanks in advance


//golles
Naif
Fixed:

Code:

<?php
$file = fopen("config.php", "r+") or die("<p class=\"red\">Fout met openen van het bestand!</p>");

$file_out = fwrite($file, "<?php\n\$title = \"{$_POST['title']}\";\n\$banner = \"{$_POST['banner']}\";\n\$backgroundimg = \"{$_POST['backgroundimg']}\";\n?>") or die("<p class=\"red\">Fout met schrijven naar config.php!<br/>Kijk a.u.b. of de CHmod goed is ingesteld!</p>");

fclose($file);
?>


Notice I added a \ before each $ which precedes a variable name inside the fwrite() function. If you dont add a \ before the $, the php phraser will perform a variable substitution(which you dont want here).
golles
hmm really stupid of me Embarassed
thanks!

I noticed that the r+ gives errors and only works if the chmod is on 777 I changed it to w+ and the chmod back to 644. can some explain why it gives errors in r+ 777 and not in w+ 644?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.