/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] String escaped twice?

Hi

On my host I see in phpinfo says that magic_quotes_gpc, magic_quotes_runtime and magic_quotes_sybase are all off. However it seem to me like “something” is escaping my data anyway. I see that phpinfo says under Configure Command ‘–enable-magic-quotes’
Is this the reason that when adding $mystring below to the db using mysql_real_escape_string I seem to get it double escaped? What is that Configure Command actually then and how can I check it like I’m trying with get_magic_quotes_gpc below ?

Thanks

[code=php]
if (get_magic_quotes_gpc ()) {
$mystring = stripslashes ( $mystring );
}
[/code]

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 10.2011 — The "--eanble_magic_quotes" means that PHP was compiled with magic_quotes_gpc enabled by default. [I]However[/I], if your php.ini (or httpd.conf) config file has it set to "off", that will override the compiler directive (much like a .htaccess file setting will override the php.ini setting).
Copy linkTweet thisAlerts:
@LuboxauthorApr 10.2011 — Ok, thanks. This means that since I see magic_quotes_gpc, magic_quotes_runtime and magic_quotes_sybase are off (thats from php.ini right?), I shouldn't get it double escaped? And my quoted code should in fact remove any "system" slashes, right?

I just don't want to remove mysql_real_escape_string in case the script moves to a different system.

Thanks
Copy linkTweet thisAlerts:
@NogDogApr 10.2011 — Ok, thanks. This means that since I see magic_quotes_gpc, magic_quotes_runtime and magic_quotes_sybase are off (thats from php.ini right?), I shouldn't get it double escaped? And my quoted code should in fact remove any "system" slashes, right?

I just don't want to remove mysql_real_escape_string in case the script moves to a different system.

Thanks[/QUOTE]


Sounds OK. I usually do what you have if I want to make sure the code is portable. In fact, I came up with this function not too long ago as something I can just include in any file to clean up get/post/cookies should they be "infected" by magic quotes:
[code=php]
<?php
/**
* Undo the damage of magic_quotes_gpc if in effect
* @return bool
*/
function fix_magic_quotes()
{
if (get_magic_quotes_gpc()) {
$func = create_function(
'&$val, $key',
'if(!is_numeric($val)) {$val = stripslashes($val);}'
);
array_walk_recursive($_GET, $func);
array_walk_recursive($_POST, $func);
array_walk_recursive($_COOKIE, $func);
}
return true;
}
[/code]

Normal usage would then simply be:
[code=php]
<?php
include 'file/with/this/function.php';
fix_magic_quotes();
/* rest of script... */
[/code]
Copy linkTweet thisAlerts:
@LuboxauthorApr 10.2011 — Ok, thanks for that function.

My problem seems to be that there is something escaping my strings even though get_magic_quotes_gpc() returns false. If php isn't escaping, who's doing it? Or is php escaping in a different way? If I check the post-variable the data is escaped already..

Thanks
Copy linkTweet thisAlerts:
@NogDogApr 10.2011 — Javascript on the client side? Using mysql_real_escape_string() twice? Using mysqli_escape_string() on bound parameters in a prepared statement?
Copy linkTweet thisAlerts:
@LuboxauthorApr 10.2011 — Ok, this was a little bit embarassing ? I'm integrated with SMF (forum software), and that was the reason. They're doing something which I now should be able to create a workaraound for. Sorry for the hassle ?

Thanks
Copy linkTweet thisAlerts:
@NogDogApr 11.2011 — Ok, this was a little bit embarassing ? I'm integrated with SMF (forum software), and that was the reason. They're doing something which I now should be able to create a workaraound for. Sorry for the hassle ?

Thanks[/QUOTE]


If you figured it out, then it's all good. ?
×

Success!

Help @Lubox spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...