fwrite adding quotes

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
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

fwrite adding quotes

Post 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 '?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The fun of dealing with magic quotes. Detect that they are on then use stripslashes().
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Post 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.
Post Reply