zander1983 Posted March 28, 2011 Share Posted March 28, 2011 Hi I have a simple form and when the user submits, php is putting a \ before every single quote entered in the field. So for example, if a user enters O'Neill, once i do $lastName = $_POST["lastname"]; $lastName comes back as: O\'Neill is there some way I can turn this off? Link to comment https://forums.phpfreaks.com/topic/231977-php-post-is-returning-single-quote-character/ Share on other sites More sharing options...
Psycho Posted March 28, 2011 Share Posted March 28, 2011 The magic_quotes_gpc setting is enabled on your server. If you have access to the php.ini file you can turn this off. If you are on a shared server you will not be able to do this. Depending on your situation it is probably better to "cleanse" your user input in a server independent manner - i.e. using a process that will work no matter what the server setting is. there is an example process in the PHP manual for this - along with other useful information on the subject. http://www.php.net/manual/en/function.get-magic-quotes-gpc.php Link to comment https://forums.phpfreaks.com/topic/231977-php-post-is-returning-single-quote-character/#findComment-1193374 Share on other sites More sharing options...
zander1983 Posted March 28, 2011 Author Share Posted March 28, 2011 yep, im on a shared server so i cant change it. This is going to be annoying! Thanks for the help Link to comment https://forums.phpfreaks.com/topic/231977-php-post-is-returning-single-quote-character/#findComment-1193431 Share on other sites More sharing options...
jcbones Posted March 28, 2011 Share Posted March 28, 2011 Put this script in a file, and include it into all processing scripts. It will strip the slashes automatically. <?php if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { function GPCStrip($arr) { if (is_array($arr)) { foreach ($arr AS $arrKey => $arrVal) { $arr[$arrKey] = GPCStrip($arrVal); } } else if (is_string($arr)) { $arr = stripslashes($arr); } return $arr; } $_GET = GPCStrip($_GET); $_POST = GPCStrip($_POST); $_COOKIE = GPCStrip($_COOKIE); if (is_array($_FILES)) { foreach ($_FILES AS $key => $val) { $_FILES[$key]['tmp_name'] = str_replace('\\', '\\\\', $val['tmp_name']); } } $_FILES = GPCStrip($_FILES); } if (function_exists('set_magic_quotes_runtime')) { set_magic_quotes_runtime(0); } ?> *note* NOT MY SCRIPT, can't remember where it came from, but it is in my library. Link to comment https://forums.phpfreaks.com/topic/231977-php-post-is-returning-single-quote-character/#findComment-1193438 Share on other sites More sharing options...
zander1983 Posted March 29, 2011 Author Share Posted March 29, 2011 thanks, this is working perfectly Link to comment https://forums.phpfreaks.com/topic/231977-php-post-is-returning-single-quote-character/#findComment-1193597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.