FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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?
Related topics
Internet Download Manager
FTP error codes -- What they mean
[RESOLVED] Awstats Error
Protect Your Site, Or suffer the consiquences
[PHP] Error link
LIST Command
Cgi #exec command returns error [Resolved]
IS my database safe
for anyone who's looking into linux, here is my old review
Computer error messages
Screwed Up PC
Lineage II (C4 chronicle)
Windows is freer than Linux
Most Ridiculous Error Messages
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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