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

How to Fix Runtime Error on Website with SDF Database?

Problem Statement Runtime error on website having Database on SDF file. Solution Start IIS...

Error 80004005 The Microsoft Jet Database Engine Cannot Open the File

Following are the possible causes of this error: This error usually occurs when database file or...

WebsitePanel error :: Web Application Gallery module is unavailable

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

Error: Fatal error: Allowed memory size of xxxxxx bytes exhausted

Sometimes you may receive the following error message while accessing your PHP page: Error :...

500 Internal Server Error

In Windows hosting, sometimes you may get error message 500 Internal Server Error for scripts...