note 111639 added to function.filter-input
| From: | magictallguy at hotmail dot com | Date: | Mon, 11 Mar 2013 12:36:26 +0000 |
| Subject: | note 111639 added to function.filter-input | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194027@lists.php.net to get a copy of this message | ||
For those that aren't aware, you can use filter_input() in a one-line if() statement:
<?php
$_GET['ID'] = filter_input(INPUT_GET, 'ID', FILTER_SANITIZE_NUMBER_INT) ?: null;
echo $_GET['ID'];
?>
Assume that $_GET['ID'] = 1 - the code above would return 1
Whereas is we assume $_GET['ID'] = 1.56&someString - the code above would return null.
For those wanting just a completely clean INT, wrap $_GET['ID'] in abs() and intval()
<?php
$_GET['ID'] = filter_input(INPUT_GET, 'ID', FILTER_SANITIZE_NUMBER_INT) ?
abs(@intval($_GET['ID'])) : null;
----
Server IP: 69.147.83.199
Probable Submitter: 82.25.95.165
----
Manual Page -- http://php.net/manual/en/function.filter-input.php
Edit -- https://master.php.net/note/edit/111639
Del: integrated -- https://master.php.net/note/delete/111639/integrated
Del: useless -- https://master.php.net/note/delete/111639/useless
Del: bad code -- https://master.php.net/note/delete/111639/bad+code
Del: spam -- https://master.php.net/note/delete/111639/spam
Del: non-english -- https://master.php.net/note/delete/111639/non-english
Del: in docs -- https://master.php.net/note/delete/111639/in+docs
Del: other reasons-- https://master.php.net/note/delete/111639
Reject -- https://master.php.net/note/reject/111639
Search -- https://master.php.net/manage/user-notes.php