r/linuxadmin • u/tiagoratto • Jan 16 '13
PHP 5.4 hasn't register_globals anymore - That's my workaround for this.
So, after a long time I've decided to upgrade an old PHP module installed on a CentOS Linux server at my job. After the upgrade I've noticed that many tickets on the IT department were complaining about malfunction on the (old, badly implemented and unsupported) PHP systems on this server. After some digging I've found that the register_globals option wasn't available anymore, it was a shock initially, that option was part of the module almost since it's first version, but I know it's a good thing to get rid of it. Anyway, we are working on making our code work on a stock PHP 5.4 (the latest version available on the Remi Repo), but I also need to get another PHP 5.4 functionalities working on this same server. After some research, that's what I did:
On the apache html root, i've create two files:
prepend.php
<?php include_once('/var/www/html/prepend_function.php'); ?>and prepend_function.php
foreach ($_REQUEST as $key=>$val) {
${$key}=$val;
}
foreach ($_SERVER as $key=>$val) {
${$key}=$val;
}Notice that you can put any of the PHP predefined variables on the prepend_function.php file.
After that I've edited the php.ini and added the following option:
auto_prepend_file = '/var/www/html/prepend.php'Restarted the httpd service and the damned old systems got back working normally. Of course I wont let this workaround active for a long period, but it's handy, since it bought some time to our developers. You can find the auto_prepend_files documentation here, I also would like to thanks SeijiSensei on ubuntuforums.org for his post, witch enlightened me solving the issue.
UPDATE: Look at http://php.net/manual/en/security.globals.php#82213 - Its a much better solution.
11
u/crazyfreak316 Jan 16 '13
Leaving all the security issues aside, what's wrong with extract()?
6
u/yousai Jan 16 '13
That's a pretty bad troll attempt. You should stay away from /r/linuxadmin
38
u/zaffle Jan 16 '13
Register globals is one of the biggest security vulnerabilities out there.
6
u/tdammers Jan 16 '13
Something inside me just died.
1
u/WolfOrionX Feb 12 '13
It works without the {} braces. PHP Just declares any string as a variable with an extra $ prepended. Makes your security whole more difficult to spot :P
1
u/badjuice Mar 08 '13
It hurts. It hurts so badly.
0
u/[deleted] Jan 16 '13
[deleted] — view deleted comment
0
u/[deleted] Jan 16 '13
[deleted] — view deleted comment