stevesimo Posted March 22, 2007 Share Posted March 22, 2007 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 More sharing options...
Lumio Posted March 22, 2007 Share Posted March 22, 2007 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. Link to comment https://forums.phpfreaks.com/topic/43806-correct-use-of-addslashes/#findComment-212678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.