phpmagic-quotesmagic-quotes-gpc

Using get_magic_quotes_gpc on PHP Version 5.2.14 or equivalent for PHP Version 6


Our site is using PHP Version 5.2.14

Lately our hoster probably changed magic-quote defenition, and I came up with the suggested solution [code bellow]

  1. Is this solution OK for PHP Version 5.2.14 ?
  2. What should I change when we upgrade to PHP version 6 ?
// Code:

function fHandleQuotes($s) {
  if (get_magic_quotes_gpc())
    return ($s);
  return (addslashes($s));
}

. . .
// Usage:

. . . 
$query = "UPDATE myTable SET myField = '" . fHandleQuotes($_POST['fieldName']) . "'";
. . . 

Solution

  • In PHP 6 magic_quotes will be removed!
    Now you can use this function.

    if(  ( function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc() ) || ini_get('magic_quotes_sybase')  ){
        foreach($_GET as $k => $v) $_GET[$k] = stripslashes($v);
        foreach($_POST as $k => $v) $_POST[$k] = stripslashes($v);
        foreach($_COOKIE as $k => $v) $_COOKIE[$k] = stripslashes($v);
    }