How does the magic_quotes_gpc setting affect the storage and retrieval of data in a MySQL database using PHP?
The magic_quotes_gpc setting in PHP automatically adds slashes to incoming data from forms, which can lead to double escaping and corrupt data when storing or retrieving it in a MySQL database. To solve this issue, you should disable the magic_quotes_gpc setting in your PHP configuration.
// Disable magic_quotes_gpc setting
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value) {
$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
Related Questions
- What are common installation problems with PHP 5 on Windows XP?
- How can cURL output be stored in a variable instead of displaying in the browser?
- In terms of user status management, what are the potential drawbacks of using a binary "active/inactive" status system, and what alternative status options could be considered for a more flexible user management approach?