Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen does filter_input() remove slashes of POST variables?
    primarykey
    data
    text
    <p>I created a small PHP-script, that runs on a server with PHP 5.2.17 and the <code>magic_quotes_gpc</code> directive enabled.</p> <p>I have no write-access to the php.ini file, and I'd like to remove all slashes from user inputs.</p> <p>This should work even if the <code>magic_quotes_gpc</code> directive is turned off (for example when moving the scripts to another server).</p> <p>It should also work recursively when arrays are submitted by the user.<br> I prefer using a built in-function.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;HP&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="POST" action="magic.php"&gt; &lt;input type="text" value="te\\&amp;quot;st" name="test1"&gt; &lt;input type="text" value="te\\&amp;quot;st" name="test2[tw&amp;quot;o]"&gt; &lt;input type="submit" value="submit"&gt; &lt;/form&gt; &lt;?php echo "&lt;pre&gt;"; echo "magic_quotes: ".get_magic_quotes_gpc()."\n"; echo "&lt;hr&gt;test1"; echo "filter_input: ".filter_input(INPUT_POST, "test1")."\n"; echo "POST: ".$_POST['test1']."\n"; echo "&lt;hr&gt;test2 (filter)"; print_r(filter_input_array(INPUT_POST))."\n"; echo "&lt;hr&gt;test2 (post)"; print_r($_POST)."\n"; echo "&lt;/pre&gt;"; ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Which gives the following result on my server:</p> <pre><code>magic_quotes: 1 filter_input: te\\"st POST: te\\\\\"st test2 (filter)Array ( [test1] =&gt; te\\"st [test2] =&gt; Array ( [tw\"o] =&gt; te\\"st ) ) test2 (post)Array ( [test1] =&gt; te\\\\\"st [test2] =&gt; Array ( [tw\"o] =&gt; te\\\\\"st ) ) </code></pre> <p>It seems that except for the array keys the slashes are removed.</p> <p>Or are the slashes never added? (<code>filter_input()</code> and <code>filter_input_array()</code> might ignore the <code>magic_quotes_gpc</code> directive, since it is deprecated; but I could not find a reference for that)</p> <p>Is the behaviour for removing/not setting the slashes of <code>filter_input()</code> and <code>filter_input_array()</code> somehow dependent on system-parameters?<br> I don't understand the warning <a href="http://www.php.net/manual/en/filter.filters.sanitize.php" rel="nofollow">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload