Reputation: 34200
All,
There is a text area say
<input type="submit">
And if a user gives the input as,
here is my name and my mail id is "[email protected]"
And when the data is posted on the server side the data is received as here is my name and my mail id is \"[email protected]\"
Backslash is added behind double quotes.Now how to encode the the data before submitting.I am using php on the server side..
Thanks.
Upvotes: 2
Views: 3347
Reputation: 83745
You can get rid of magic quotes also in PHP if your web hosting provider doesn't allow you to disable it in php.ini file. Put this code on top of your PHP script:
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value) {
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
Upvotes: 2
Reputation: 7752
You probably have magic quotes enabled on your system. This is not a good thing.
Upvotes: 1
Reputation: 401172
It looks like the directive magic_quote_gpc
is enabled on your server :
When magic_quotes are on, all ' (single-quote), " (double quote),
(backslash) and NUL's are escaped with a backslash automatically.
stripslashes
About that, you can read the section Disabling Magic Quotes.
Upvotes: 2
Reputation: 1742
Disable magic_quotes in php.ini or use stripslashes($text)
in PHP to remove slashes.
Upvotes: 1
Reputation: 11278
this is magic_quotes_gpc kicking in - to remove it just disable it in php.ini or remove it using stripslashes($your_var);
though bear in mind that this is a (lousy) security feature of php, but when storing the data to a database you should use the respective escape functions to prevent sql injections anyway and when showing user-posted data your sanitizing function should prevent xss injections.
Upvotes: 3