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

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

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

Various Outlook/Outlook Express Error Codes

Error Code Description 0x800CCCF4 HTTPMail Your outlook settings may...

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 do I fix HTTP Error 404 on my website?

Following are some of the most common reasons and solutions of 404 error. You might be typing...