ID: 17428 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] Status: Open Bug Type: Documentation problem Operating System: Windows XP PHP Version: 4.2.1 New Comment:
Using import_request_variables() is close, but since it became available in PHP 4.1.0 it's not ideal, and it only deals with GPC. Using extract() will be closer, something like: // register a lot of vars if register_globals = off 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); } } } This does not rely on the variable_order directive, which I prefer not to do, but it could :) Maybe someone wants to add ENV, or subtract some, or add a prefix. All possabilities to think about. Also note that default for register_globals became "off" in PHP 4.2.0 but as of PHP 4.1.0 it was recommended to have it off. Previous Comments: ------------------------------------------------------------------------ [2002-05-25 19:27:41] [EMAIL PROTECTED] I was a bit surprised as well, as there were no hints on making old scripts compatible to PHP's new behaviour. In fact, a simple import_request_variables("gpc"); inserted somewhere at the beginning of your script (usually every script has a config.php, which is included by all other files) would be a good workaround until these scripts are rewritten to "register_globals=off". ------------------------------------------------------------------------ [2002-05-25 19:12:54] [EMAIL PROTECTED] The intro tutorial says the following: One of the most powerful features of PHP is the way it handles HTML forms. The basic concept that is important to understand is that any form element in a form will automatically result in a variable with the same name as the element being created on the target page. But it is not true any more, since the global variable is turned off by default since 4.1.2 and it is said that it is bad practice to turn it on. There are so many new PHP programmers who stumbled on this one. The scripts they write according to the tutorial simply do not work. Also, there are a lot of scripts written before 4.1.2 that use this feature and they won't work after being downloaded by people who are not familiar with PHP. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17428&edit=1