note 56321 added to language.variables.predefined

From: Date: Tue, 30 Aug 2005 16:29:23 +0000
Subject: note 56321 added to language.variables.predefined
Groups: php.notes 
Request: Send a blank email to php-notes+get-94437@lists.php.net to get a copy of this message
Following up on webdesign at benking dot com, I might do this using array functions, depending on the situation. It seems a bit simpler. $allowed_args = array ( f_name, l_name, subject, msg ); foreach ( $_POST as $k=>$val ) { if ( in_array ( $k, $allowed_args ) ) $$k = $val; } // Another way (may have typos, as I just typed this in without testing.) foreach ( $_POST as $k=>$val ) { if ( ! in_array ( $k, $allowed_args ) ) { unset ($_POST[$k]); } // This is also a good place to do sanity checks } // Now all disallowed POST variables are deleted. // We can insert the good ones into our name space. extract ($_POST,EXTR_PREFIX_ALL,"P"); // The new variables will be named, e.g., $P_f_name, $P_subject. ---- Manual Page -- http://www.php.net/manual/en/language.variables.predefined.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56321 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56321&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56321&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56321&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56321&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56321&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56321&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56321&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94437) next »