note 38781 deleted from function.get-magic-quotes-gpc by didou
| From: | didou@php.net | Date: | Wed, 07 Jan 2004 10:43:54 +0000 |
| Subject: | note 38781 deleted from function.get-magic-quotes-gpc by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63058@lists.php.net to get a copy of this message | ||
Note Submitter: eric_taylor atsymbol morgan-cain dot com
----
This may be a somewhat unique approach (and it certainly seems to work)--basically, I reasoned the
only time that I'm having trouble with magic_quotes_gpc is when some of my data came from
$_POST and some of it came fresh off the SQL database. In that case, I have a mix of magic-quoted
and non-magic-quoted data, which is the sticky issue.
My solution is to ereg for any unslashed single-quotes in my variables before attempting an SQL
insert or update with my variables:
function maybeslash( &$element ) {
if( is_array( $element ) ) {
// recurse any arrays in our variable
array_map( "maybeslash", $element );
} else {
// if our variable has a single-quote with no slash b4 it, addslash
if( ereg( "^']'", $element ) ) {
$element = addslashes( $element );
}
}
}
When it's over, everything is magic-quote compatiblized... :)