Jump to content

Stripslashes as a back up?


floridaflatlander

Recommended Posts

I have a small site and right know for strings I use mysqli_real_escape_string. However when moving me to another server my provider left magic_qoutes on. So strings started adding slashes in code I wrote (but not in wordpress and smf for some reason(?)).

 

I've emailed them and informed then that I wanted the m_qoutes off. This is the second time this has happened in a year and a half.

 

Anyway, would it be bad form to have stripslashes() just before mysqli_real_escape_string as back up?

Link to comment
Share on other sites

I usually check to make sure stripslashes exists. Maybe I'm just paranoid. Can also check the version number to see if the rest of it is even necessary.

 

if( PHP_VERSION < 5.4 && ini_get('magic_quotes_gpc') ) {
if( function_exists('stripslashes') ) {
	$data = stripslashes($data);
} else {
                 // figure out what to do with slashes if stripslashes is non-existent . . .
}
$data = mysqli_real_escape_string($dbc, $data);

Link to comment
Share on other sites

Yeah, get_magic_quotes_gpc() is what I meant. I knew something seemed off. Should have looked at one of the scripts I use it in instead of going by memory. So it should be:

 

if( PHP_VERSION < 5.4 && get_magic_quotes_gpc() ) {
if( function_exists('stripslashes') ) {
	$data = stripslashes($data);
}
}
$data = mysqli_real_escape_string($dbc, $data);

Link to comment
Share on other sites

Stripslashes shouldn't be deprecated, and it's built into the core of php.

 

Definitely paranoid ;)

 

Now I remember why I explicitly check for it. If it's been disabled in the php.ini file for some stupid reason, a warning is generated if you try to use it.

Link to comment
Share on other sites

Stripslashes shouldn't be deprecated, and it's built into the core of php.

 

Definitely paranoid ;)

 

Now I remember why I explicitly check for it. If it's been disabled in the php.ini file for some stupid reason, a warning is generated if you try to use it.

 

Is it just slashes-functions that can be disabled in the ini? Or any core functions? That's kind of scary - terrible band-aid to fix any slash issues a script might have I guess?

Link to comment
Share on other sites

I think if I ever ran into a system that disabled active, working, safe core functionality I would suggest that the owners fire their admins.

 

I can understand why they included that ability through the INI though, though black-listing is generally much more difficult than white.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.