How to emulate register_globals in PHP 5.4

During our recent Linux server migration task, we faced following strange issue:

Some websites built on older versions of PHP 5.3.0 or earlier could not fatched the several database records. After some investigation we found that problem was with Register_globals (). Register_globals () is DEPRECATED in PHP 5.3.0 and REMOVED in PHP 5.4. Customer has used Register_globals=ON in his code. If you set Register_globals=ON in your code, values submitted through a form, via POST or GET will automatically be accessible via variable in the PHP script named after the name of the input field.

For example:

If you have URL like;........ http://www.xyz.com/var_name.php?user_id=10 and automaticaly you'll have $user_id = 10 in PHP.

Customer was using such variables in his SQL queries. In our new Linux server, target PHP verson was set to PHP 5.4 in which Register_globals is removed. Hence, SQL queries could not fatch the passed parameters. As a resolutiuon, we advised customer to emulate register_globals with using extract in global scope like as follows:

extract($_REQUEST); ............OR create an independent function like as follows:

function xyz()
{
foreach ($_REQUEST as $key => $val)
{
global ${$key};
${$key} = $val;
}
}
  • 0 Users Found This Useful

Was this answer helpful?

Related Articles

Fix - Session Timeout after some seconds in umbraco installation

Problem statement Umbraco installation is throwing 401 error while uploading images....

Operation must use an updateable query Microsoft OLE DB Provider for ODBC Drivers error '80004005' .[Microsoft] [ODBC Microsoft Access Driver]

This error usually occurs when you try to insert or update data in MS Access database i.e. you do...

WebsitePanel error :: Web Application Gallery module is unavailable

You may receive the following error while installing any Microsoft Applications from Microsoft...

Error 3241: The media family on device is incorrectly formed

Sometimes we may receive the below error message when restoring the database from the backup file...