I have read about this and people ask this a bit too often.
lets say u have a input
$_POST['json_txt'] = "{
bar:'value 1',
foo:{
baz:'value 2',
fuz:'value 3'
}
}";
We can validate this input using the php function json_last_error ();
Q 1 = Shouldn't there be another option where we can sanitise this json object?
Q2 = Also is the json_last_error();开发者_开发百科
the absolute way to correctly validate the input and save it to a db (mysql)?
Are you saving the entire JSON object to the database, or individual parts? You can sanitize a variable (either one from the decoded JSON object or the JSON object itself) with mysql_real_escape_string() before inserting it into the database.
精彩评论