Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • get_magic_quotes_gpc() function is deprecated, please help

    • 2
    • 2
    • 0
    • 2
    • 0
    • 0
    • 0
    • 4.58k
    Answer it

    Hi everybody,

    i am a newbie php programmer.

    get_magic_quotes_gpc() function is deprecated; Is there any function or way to create backslahes to prevent sql injection?

    any tips and advises will help. thanks

    /=======THIS IS THE FUNCTION FROM THE PHP MANUAL function quote_smart($value, $handle) { // Stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote if not integer if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value, $handle) . "'"; } return $value; }

    //=======END OF FUNCTION FROM THE PHP MANUAL

 2 Answer(s)

  • In place of get_magic_quotes_gpc(), you can use htmlentities() method. It will help to prevent sql injection. e.g.

    if (isset($_POST)) {
        $post = new httppost($_POST);
        echo htmlentities($post->value['field_name']);
    }
    

    If still you facing any issue. Let me know.

  • Hi,

    The issue is that you are using PHP version 5.4 or above which has the function deprecated.

    The 2 options you have. 1. First is to switch back to version 5.3 or less. 2. Second is to enclose the code under a condition which checks PHP version.

    function quote_smart($value, $handle) { 
    // Stripslashes 
    if(phpversion() < "5.3")
    {
    if (get_magic_quotes_gpc()) { 
        $value = stripslashes($value); 
    } 
    }
    // Quote if not integer 
    if (!is_numeric($value)) { 
        $value = "'" . mysql_real_escape_string($value, $handle) . "'"; 
    } 
    return $value; 
    }
    

    Hope this helps.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: