Slashes in Forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • StevePBurgess@gmail.com

    Slashes in Forms

    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
    below).

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

  • Mara Guida

    #2
    Re: Slashes in Forms

    StevePBurgess@g mail.com wrote:[color=blue]
    > Ok. I have checked the magic quotes is on.[/color]

    Can't you turn it off?
    [color=blue]
    > A PHP script processes [the POST data]. If there any errors the input
    > is urlencoded and returned to the webpage[/color]

    urlencoded? spaces shown as "+"?

    <snip>[color=blue]
    > Any thoughts?[/color]


    This works for me, both with magic_quotes_gp c Off or On

    ========
    <?php
    if (get_magic_quot es_gpc()) {
    function magic_UNquote($ txt) {
    return stripslashes($t xt);
    }
    } else {
    function magic_UNquote($ txt) {
    return $txt;
    }
    }
    echo '$_POST[\'txt\'] = [', $_POST['txt'], "]<br />\n<br />\n";
    $val = (isset($_POST['txt']) && ($_POST['txt'] !=
    ''))?(magic_UNq uote($_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" />
    </form>
    ========

    HTH

    Comment

    • StevePBurgess@gmail.com

      #3
      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
      suggestions.

      Comment

      Working...