/    Sign up×
Community /Pin to ProfileBookmark

mysql_real_escape_string

Hi I’m doing some php security and have been reading up on using mysql_real_escape_string instead of addslashes. Apparently mysql_real_escape_string is more secure than addslashes and you don’t have to decode your database entries when you want to call them back out – this only works however if you have magic_quotes_gpc turned off. So my question is how do you test to see if it’s working??

Sorry if it’s a stupid question!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscNov 18.2008 — By default, I have a php.ini file that I upload to my site that turns it off.

My php.ini file
<i>
</i>magic_quotes_gpc = off


If you're host doesn't allow you to have your own php.ini files, however, check it like this

[code=php]
if(!get_magic_quotes_gpc()) {
//this means its disabled, so you can use mysql_real_escape_string in here
}
[/code]


http://ca.php.net/manual/en/function.get-magic-quotes-gpc.php
Copy linkTweet thisAlerts:
@NogDogNov 18.2008 — You can take it one step further and undo the "damage" if it's turned on:
[code=php]
if(get_magic_quotes_gpc())
{
function undo_magic_quotes(&$val, $key)
{
$val = stripslashes($val);
}
if($_POST) { array_walk_recursive($_POST, 'undo_magic_quotes'); }
if($_GET) { array_walk_recursive($_GET, 'undo_magic_quotes'); }
if($_COOKIE) { array_walk_recursive($_COOKIE, 'undo_magic_quotes'); }
}
[/code]

Of course, it will be more efficient if you can explicitly turn it off in your configuration and not have to do this extra processing. ?
×

Success!

Help @cannon303 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...