Register Globals Emulator for PHP

If your webhosting turned register-globals off and you are still using a script/software which requires register-globals on you have a problem. But there is an easy solution: Just put this code at the top of your php script(s). Attention!!! "register_globals=on" means a huge security risk. Do not turn it on unless you know what are you doing!
Technorati Profile

foreach(array($_GET, $_POST, $_COOKIE) as $k=>$v){
foreach($v as $k2=>$v2){
$$k2 = $v2;

You can improve this to build a small web-firewall and prevent sql-injection etc. You can add some code and strip unwanted html-javascript tags with this.

Submitted by Anonymous (not verified) on Tue, 07/28/2009 - 15:54


Having register_globals = on does not mean a huge security risk. Also, the provided code does not emulate it properly so instead consider using an example from the manual: