Page 1 of 1

fwrite adding quotes

Posted: Sun Apr 23, 2006 9:14 pm
by waradmin
I have a script that takes a config file and edits it.

Then the edit's are passed using a form and POST to a file named update_config.php, the code is:

Code: Select all

<? include('../../config.php'); ?>
<?php
$ip = $_POST['ip'];
$submit = $_POST['submit'];
unlink("../config.php");
touch("../config.php");
$filename = "../config.php";
$fp = fopen($filename, "w") or die("Could not open $filename");
fwrite($fp, "$ip");
fclose($fp);
echo "Updated, please <a href=\"configure.php\">click here</a> to go back";
?>
But when it writes the new config file, it takes a variable such as

Code: Select all

$name = "steve";
and changes it to

Code: Select all

$name = \"steve\";
and if theres something like

Code: Select all

$blogname = "Steve's Blog";
it changes it to

Code: Select all

$blogname = \"Steve\'s Blog\";
How can I get it not to add the \ before the " and '?

Posted: Sun Apr 23, 2006 10:24 pm
by feyd
The fun of dealing with magic quotes. Detect that they are on then use stripslashes().

Posted: Wed Apr 26, 2006 10:53 pm
by waradmin
Thats not working, I assume because I am doing it wrong, here is all of the code for the script:

Code: Select all

<?php
include("validate.php");
?>
<? include('../../config.php'); ?>
<?php
$ip = $_POST['ip'];
$submit = $_POST['submit'];
unlink("../config.php");
touch("../config.php");
$filename = "../config.php";
$fp = fopen($filename, "w") or die("Could not open $filename");
stripslashes($ip);
fwrite($fp, "$ip");
fclose($fp);
echo "Updated, please <a href=\"configure.php\">click here</a> to go back";
?>
Thanks in advance if you can offer support.