Jump to content

Recommended Posts

Ive just turned magic_quotes on via php.ini

 

as a result any time a " or ' is being inserted to the database its being parsed with a forwarding \

 

Perfect!

 

However, I have so many bits of information that does not have the stripslashes() function

 

Rather than add to every variable, is there anyway to make php remove the slashes after its been pulled from the database

 

Please advise

Link to comment
https://forums.phpfreaks.com/topic/64153-solved-strip-slashes/
Share on other sites

Im explaining this with an example so u should have the idea:

 

$query = mysql_query("SELECT * FROM table");
$values = mysql_fetch_array($query);
$values = array_map('stripslashes', $values);

 

That should run stripslashes over all of the values of the array $values. Anyway the array $values may have a lot of data which will not even display, so it may slow a bit the proccess. Myself i use stripslashes for each variable i print.

 

Also about the magic_quotes_gpc, every php security article or book ive read tells that magic_quotes are evil lol. U could consider manually cleaning data, probably using the more secure mysql_real_escape_string then just staying relaxed and let the system make the hard work :D

Link to comment
https://forums.phpfreaks.com/topic/64153-solved-strip-slashes/#findComment-319721
Share on other sites

Why do you want magic_quotes on?

 

The slashes that php adds to your input is not suitable for inserting into MySQL. It is better to use a native solution, ie, mysql_real_escape_string. Even better, for portability, use a function to detect for magic_quotes and stripslashes accordingly.

 

<?php
function clean_string( $value, $DB )
{
if ( get_magic_quotes_gpc() )
{
	$value = stripslashes( $value );
}
// escape things properly
return mysql_real_escape_string( $value, $DB );
}
?>

 

According to php.net

http://us.php.net/manual/en/security.magicquotes.whynot.php it affects performance and portability.

 

PHP6 will also removing magic_quotes completely.

Link to comment
https://forums.phpfreaks.com/topic/64153-solved-strip-slashes/#findComment-319725
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.