MyWrestlingNetwork
New Member
I'm writing a app that needs to be portable. I know I should disable magic quotes on the PHP configuration but in this case I don't know if I can do that, so I'm using the following code:\[code\]if (get_magic_quotes_gpc() === 1){ $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); while (list($key, $val) = each($process)) { foreach ($val as $k => $v) { unset($process[$key][$k]); if (is_array($v)) { $process[$key][stripslashes($k)] = $v; $process[] = &$process[$key][stripslashes($k)]; } else { $process[$key][stripslashes($k)] = stripslashes($v); } } } unset($process);}\[/code\]To simplify the process of disabling magic quotes I had the following idea:\[code\]if (get_magic_quotes_gpc() === 1){ foreach (array('GET', 'POST', 'COOKIE', 'REQUEST') as $array) { ${'_'.$array} = unserialize(stripslashes(serialize(${'_'.$array}))); }}\[/code\]But I tried and I got an error I'm unable to understand, for instance with \[code\]?name=O'Reilly\[/code\]:\[code\]serialize($_GET); // a:1:{s:4:"name";s:9:"O\'Reilly";}stripslashes(serialize($_GET)); // a:1:{s:4:"name";s:9:"O'Reilly";}\[/code\]But \[code\]unserialize(stripslashes(serialize($_GET)))\[/code\] gives me this weird error:Notice: unserialize(): Error at offset 30 of 32 bytesEDIT: Due to the length attribute in \[code\]serialize()\[/code\] I changed the code to use JSON functions:\[code\]if (get_magic_quotes_gpc() === 1){ foreach (array('GET', 'POST', 'COOKIE', 'REQUEST') as $array) { ${'_' . $array} = json_decode(stripslashes(json_encode(${'_' . $array})), true); }}\[/code\]However now the \[code\]$_GET\[/code\] array is coming up empty, can anyone explain me why?