note 107802 added to function.stripslashes
| From: | tarmo at goyf dot de | Date: | Tue, 06 Mar 2012 14:58:15 +0000 |
| Subject: | note 107802 added to function.stripslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186508@lists.php.net to get a copy of this message | ||
When matching strings with approstrophes against the mysql database, my query kept failing while it
worked fine when I copied the same query directly to perform the database query. After several hours
I found that stripslashes() made the string longer and hence it wasn't "equal" for
the query.
This code shows the behavior (copy into "test.php"). Replacing stripslashes worked for me.
<?php
echo '<h2>Post-Data</h2>';
var_dump($_POST);
$f1 = trim(filter_var(stripslashes($_POST[form]), FILTER_SANITIZE_STRING));
echo '<h2>stripslashes</h2>';
var_dump($f1);
$f2 =
trim(str_replace("|","'",filter_var(str_replace("\'","|",$_POST[form]),
FILTER_SANITIZE_STRING)));
echo '<h2>workaround</h2>';
var_dump($f2);
echo '<form action="test.php" method="post">
<input type="text" name="form">
<input type="submit">
</form>';
?>
Entering "foo'bar" creates this output:
// Post-Data
// array(1) { ["form"]=> string(8) "foo\'bar" }
// stripslashes
// string(11) "foo'bar"
// workaround
// string(7) "foo'bar"
----
Server IP: 85.214.154.209
Probable Submitter: 81.209.149.130
----
Manual Page -- http://www.php.net/manual/en/function.stripslashes.php
Edit -- https://master.php.net/note/edit/107802
Del: integrated -- https://master.php.net/note/delete/107802/integrated
Del: useless -- https://master.php.net/note/delete/107802/useless
Del: bad code -- https://master.php.net/note/delete/107802/bad+code
Del: spam -- https://master.php.net/note/delete/107802/spam
Del: non-english -- https://master.php.net/note/delete/107802/non-english
Del: in docs -- https://master.php.net/note/delete/107802/in+docs
Del: other reasons-- https://master.php.net/note/delete/107802
Reject -- https://master.php.net/note/reject/107802
Search -- https://master.php.net/manage/user-notes.php