With a little side of applesauce...

Monday, February 12, 2007

PHP - removing $_POST/$_GET prefixes from variables

I know that JP has sent this code to me a thousand times, but I still had to go looking for it again tonight... :P

 <?php
// register vars if register_globals disabled
if ( !ini_get( 'register_globals')) {
$types_to_register = array( 'GET', 'POST',
'COOKIE'
, 'SESSION', 'SERVER');
foreach ($types_to_register as $type ) {
if (@ count(${ 'HTTP_' . $type . '_VARS'}) > 0) {
extract(${ 'HTTP_' . $type . '_VARS'},
EXTR_OVERWRITE);
}
}
}
?>

http://www.artbuilders.com/Weblogs_Gintz/Archives/000053.html

No comments: