note 100353 added to function.get-magic-quotes-gpc
| From: | rickm707 at gmail dot com | Date: | Sun, 10 Oct 2010 21:15:37 +0000 |
| Subject: | note 100353 added to function.get-magic-quotes-gpc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173118@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:
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.
----
Server IP: 208.69.120.55
Probable Submitter: 69.20.173.13
----
Manual Page -- http://www.php.net/manual/en/function.get-magic-quotes-gpc.php
Edit -- https://master.php.net/note/edit/100353
Del: integrated -- https://master.php.net/note/delete/100353/integrated
Del: useless -- https://master.php.net/note/delete/100353/useless
Del: bad code -- https://master.php.net/note/delete/100353/bad+code
Del: spam -- https://master.php.net/note/delete/100353/spam
Del: non-english -- https://master.php.net/note/delete/100353/non-english
Del: in docs -- https://master.php.net/note/delete/100353/in+docs
Del: other reasons-- https://master.php.net/note/delete/100353
Reject -- https://master.php.net/note/reject/100353
Search -- https://master.php.net/manage/user-notes.php