note 128125 added to function.filter-input-array

From: Date: Wed, 18 Jan 2023 22:56:52 +0000
Subject: note 128125 added to function.filter-input-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-220080@lists.php.net to get a copy of this message
<?php /** * Filter out non-allowed parameters in the request input and protect parameter values against XSS * * @param int $type INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, INPUT_ENV * @param array $allowed_params * @link https://www.php.net/manual/en/function.filter-input-array.php * @return array */ function sanitize_input_array($type, array $allowed_params) { return filter_input_array($type, array_fill_keys($allowed_params, array( 'filter' => FILTER_CALLBACK, 'options' => function ($value) { return trim(strip_tags($value)); } ))); } /* Usage: http://***.com/index.php?full_name=Slim%20O'Reilly&email=%20<script>alert('xss');</script>%20 &array[][]=<b>10</b>&submit=Send $allowed_params = array('submit', 'full_name', 'email', 'array', 'other'); $post = sanitize_input_array(INPUT_POST, $allowed_params); Result: var_dump($post); array(6) { 'submit' => string(4) "Send" 'email' => string(13) "alert('xss');" 'array' => array(1) { [0] => array(1) { [0] => string(2) "10" } } 'full_name' => string(17) "Slim O'Reilly" 'other' => NULL } */ ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.158.213 (proxied: 2604:3d08:5e7b:8850:c017:ed8b:83c5:85f9) ---- Manual Page -- https://php.net/manual/en/function.filter-input-array.php Edit -- https://main.php.net/note/edit/128125 Del: integrated -- https://main.php.net/note/delete/128125/integrated Del: useless -- https://main.php.net/note/delete/128125/useless Del: bad code -- https://main.php.net/note/delete/128125/bad+code Del: spam -- https://main.php.net/note/delete/128125/spam Del: non-english -- https://main.php.net/note/delete/128125/non-english Del: in docs -- https://main.php.net/note/delete/128125/in+docs Del: other reasons-- https://main.php.net/note/delete/128125 Reject -- https://main.php.net/note/reject/128125 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220080) next »