Slashes in Forms

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Ok. I have checked the magic quotes is on. I have a form on my web
page. The input from this is sent (by POST) to the server. A PHP script
processes it. If there any errors the input is urlencoded and returned
to the webpage with the form in the URL. I am not using add or strip
slashes in my script (except for the testing I did that is explained

If the user inserts slashes or double quotes - when these are returned
to the form they are slashed. If one backslash is inserted, 4
backslashes appear when the form is redisplayed. If I enter a double
quote this is returned as 3 backslashes (the double quote disappears).

If I stripslashes() before returning the input to the form, one
backslash becomes 2 backslashes and a double quote is returned as 1
backslash (but again the double quote disappears).

Any thoughts?

Thanks, in anticipation....

Re: Slashes in Forms wrote:
Quoted text here. Click to load it

Can't you turn it off?

Quoted text here. Click to load it

urlencoded? spaces shown as "+"?

Quoted text here. Click to load it

This works for me, both with magic_quotes_gpc Off or On

if (get_magic_quotes_gpc()) {
  function magic_UNquote($txt) {
    return stripslashes($txt);
} else {
  function magic_UNquote($txt) {
    return $txt;
echo '$_POST['txt'] = [', $_POST['txt'], "]<br />\n<br />\n";
$val = (isset($_POST['txt']) && ($_POST['txt'] !=
''))?(magic_UNquote($_POST['txt'])):('three quotes: """; three single
quotes: '''; three slashes: ///; three backslashes: \\; and
nothing more!');
$val = str_replace('"', '&quot;', $val);
echo '$val = [', $val, "]<br />\n<br />\n";
<form action="" method="post">
<input type="text" name="txt" size="120" value="<?php echo $val; ?>"
/><input type="submit" />


Re: Slashes in Forms

by urlencoded i just mean i use the URLENCODE() function on the data
before returning it to the browser.

will have a go at what you've suggested above. thanks for your

Site Timeline