开发者

php json check validation / sanitise

开发者 https://www.devze.com 2023-02-05 00:29 出处:网络
I have read about this and people ask this a bit too often. lets say u have a input $_POST[\'json_txt\'] = \"{

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消