phpLiteAdmin error

The following error was output in the database management tool.

PHP Deprecated:  Function get_magic_quotes_gpc() is deprecated in /phpliteadmin.php

The relevant section is below.

PHP
if (get_magic_quotes_gpc()) {
	$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);
}

Warning: Avoid using get_magic_quotes_gpc() as it will be removed in PHP 7.4 and later. The tool remains functional, but error logs were being generated.

The code after the fix is below. The above can be commented out.

PHP
$process = [&$_GET, &$_POST, &$_COOKIE, &$_REQUEST];
foreach ($process as &$global) {
	foreach ($global as $key => &$value) {
		$newKey = stripslashes($key);
		
		if (is_array($value)) {
			array_walk_recursive($value, function(&$item) {
				$item = stripslashes($item);
			});
		} else {
			$value = stripslashes($value);
		}

		if ($newKey !== $key) {
			$global[$newKey] = $value;
			unset($global[$key]);
		}
	}
}
unset($process);

If you modify the code after applying the countermeasure, you can maintain security while removing backslashes without generating error logs in PHP 7.4 and later.

To briefly explain the process: Even with Magic Quotes disabled, it executes the processing, applies stripslashes() to the array keys and values to remove backslashes. It then recursively processes nested arrays, removes backslashes from their keys, and reassigns them with new keys. Finally, it deletes the original keys using unset() to replicate the behavior of the original code.

In summary, you can remove backslashes without relying on Magic Quotes.

Leave a comment on the article