note 123334 added to filter.filters.sanitize
| From: | darrenatdaz-webdotcom@php.net | Date: | Mon, 12 Nov 2018 12:31:48 +0000 |
| Subject: | note 123334 added to filter.filters.sanitize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209671@lists.php.net to get a copy of this message | ||
For those looking for a simple way around filtering POST forms that have textarea elements in them.
If you also need tab for example you can extend quite easily.
<?php
//create an array of all relevant textareas
$textareas = array("ta1");
foreach($_POST as $k => $v)
{
$v = trim($v);//so we are sure it is whitespace free at both ends
//preserve newline for textarea answers
if(in_array($k,$textareas))$v=str_replace("\n","[NEWLINE]",$v);
//sanitise string
$v = filter_var($v, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH |
FILTER_FLAG_STRIP_BACKTICK);
//now replace the placeholder with the original newline
$_POST[$k] = str_replace("[NEWLINE]","\n",$v);
}
//simple form for testing submital
?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Filter test</title>
</head>
<body>
<form action="" method="post">
<p>
<textarea name="ta1" cols="30" rows="10"><?php echo
$_POST['ta1']; ?></textarea>
</p>
<p>
<input type="text" name="txt1" size="30" value="<?php
echo $_POST['txt1']; ?>" />
</p>
<p>
<input type="submit" />
</p>
</form>
</body>
</html>
----
Server IP: 208.43.231.9
Probable Submitter: 195.224.84.74
----
Manual Page -- http://php.net/manual/en/filter.filters.sanitize.php
Edit -- https://master.php.net/note/edit/123334
Del: integrated -- https://master.php.net/note/delete/123334/integrated
Del: useless -- https://master.php.net/note/delete/123334/useless
Del: bad code -- https://master.php.net/note/delete/123334/bad+code
Del: spam -- https://master.php.net/note/delete/123334/spam
Del: non-english -- https://master.php.net/note/delete/123334/non-english
Del: in docs -- https://master.php.net/note/delete/123334/in+docs
Del: other reasons-- https://master.php.net/note/delete/123334
Reject -- https://master.php.net/note/reject/123334
Search -- https://master.php.net/manage/user-notes.php