note 115995 added to function.array-walk

From: Date: Fri, 24 Oct 2014 11:52:56 +0000
Subject: note 115995 added to function.array-walk
Groups: php.notes 
Request: Send a blank email to php-notes+get-200726@lists.php.net to get a copy of this message
/* You can use array_walk to secure your php-code and avoid it against php/html-injection. This sample secures incoming user-data: */ <?php array_walk($_POST, 'secureInput'); array_walk($_GET, 'secureInput'); array_walk($_REQUEST, 'secureInput'); array_walk($_FILES, 'secureInput); function secureInput(&$value, $key) { $value = trim($value); // removes blank space at beginning an end $value = strip_tags($value); // removes all HTML- an PHP-commands } ?> If you want to allow some HTML- or PHP-commands, use this: $value = strip_tags($value, '<p><br>'); // removes all HTML- an PHP-commands, excepted <p></p> and <br /> Tags. NOTE: it is important to add the "&" infront of $value in the function! Otherwhise the function won't remove the HTML- and PHP-code. ---- Server IP: 72.52.91.14 Probable Submitter: 85.177.161.127 ---- Manual Page -- http://php.net/manual/en/function.array-walk.php Edit -- https://master.php.net/note/edit/115995 Del: integrated -- https://master.php.net/note/delete/115995/integrated Del: useless -- https://master.php.net/note/delete/115995/useless Del: bad code -- https://master.php.net/note/delete/115995/bad+code Del: spam -- https://master.php.net/note/delete/115995/spam Del: non-english -- https://master.php.net/note/delete/115995/non-english Del: in docs -- https://master.php.net/note/delete/115995/in+docs Del: other reasons-- https://master.php.net/note/delete/115995 Reject -- https://master.php.net/note/reject/115995 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200726) next »