note 56321 deleted from language.variables.predefined by sean

From: Date: Wed, 31 Aug 2005 00:03:27 +0000
Subject: note 56321 deleted from language.variables.predefined by sean
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-94471@lists.php.net to get a copy of this message
Note Submitter: garyb at fxt dot com Reason: bad code ---- 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.

« previous php.notes (#94471) next »