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....

500 Internal Server Error

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

How to Fix Runtime Error on Website with SDF Database?

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

WebsitePanel error :: Web Application Gallery module is unavailable

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

Orchard CMS Error - Failure - Downloaded file failed signature verification and may have been tampered with

You may face following errors while installing ORCHARD CMS from WebsitePanel's web application...