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

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

Microsoft OLE DB Provider for ODBC Drivers error '80040e10' [Microsoft][ODBC Microsoft Access 97 Driver] Too few parameters. Expected 1

This error occurs because the field name that you used in the query syntax does not exist. Often...

How to Fix Runtime Error on Website with SDF Database?

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

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

Server Error in '/' Application in WebsitePanel :: Windows Server 2003 VPS

You may receive the following errors when running WebsitePanel installed on Windows 2003 server:...