note 100353 modified in function.get-magic-quotes-gpc by danbrown

From: Date: Sun, 10 Oct 2010 21:36:23 +0000
Subject: note 100353 modified in function.get-magic-quotes-gpc by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-173119@lists.php.net to get a copy of this message
For many people, including myself, the problem is not needing to remove escape characters, but simply to know if they are already in place. In my case, I WANT user input to be properly escaped, but I don't want to do it twice. In cases like this, here's my solution: <?php function conditional_escape ($str) { /* Automatic escaping is highly deprecated, but many sites do it anyway to protect themselves from stupid customers. */ if (get_magic_quotes_gpc()) { /* Apache automatically escaped the string already. */ return $str; } /* Replace the following line with whatever function you prefer to call to escape a string. */ return mysqli_real_escape_string ($link, $str); } ?> Example: <?php $username = conditional_escape ($_POST['Username']); $password = conditional_escape ($_POST['Password']); $email_address = conditional_escape ($_POST['Email_Address']); ?> Hope this helps. --was-- For many people, including myself, the problem is not needing to remove escape characters, but simply to know if they are already in place. In my case, I WANT user input to be properly escaped, but I don't want to do it twice. In cases like this, here's my solution: function conditional_escape ($str) { /* Automatic escaping is highly deprecated, but many sites do it anyway to protect themselves from stupid customers. */ if (get_magic_quotes_gpc()) { /* Apache automatically escaped the string already. */ return $str; } /* Replace the following line with whatever function you prefer to call to escape a string. */ return mysqli_real_escape_string ($link, $str); } Example: $username = conditional_escape ($_POST['Username']); $password = conditional_escape ($_POST['Password']); $email_address = conditional_escape ($_POST['Email_Address']); Hope this helps. http://php.net/manual/en/function.get-magic-quotes-gpc.php

« previous php.notes (#173119) next »