Jump to content

Correct Use Of AddSlashes


stevesimo

Recommended Posts

Hi, I have a question regarding the use of the addslashes function.

 

When reading in values submmitted by a form, do you use addslashes just on string values or on any value regardless of type.  I have a double value and a date value and am not sure whether I need to include these in my code block which addslashes to the submitted values.

 

Thanks, Steve (Blackpool)

Link to comment
https://forums.phpfreaks.com/topic/43806-correct-use-of-addslashes/
Share on other sites

Hello!

I made it like this:

If magic_quotes is on I strip all slashes of values:

	if (get_magic_quotes_gpc()) {
	$_POST = array_map('stripslashesinarray', $_POST);
	$_GET = array_map('stripslashesinarray', $_GET);
	$_COOKIE = array_map('stripslashesinarray', $_COOKIE);
	$_REQUEST = array_map('stripslashesinarray', $_REQUEST);
}
function stripslashesinarray($value) {
	return (is_array($value) ? array_map('stripslashesinarray', $value):stripslashes($value));
}

So if magic quotes is off, it doesn't strip slashes because there are no slashes to escape ;) only if the user wrote some quotes.

 

So now you use addslashes to escape those quotes.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.