ユーザーがデータをコピーして入力フォームに貼り付けると、次のような文字が表示されることがあります。
don’t," 開始引用符および "終了引用符など ...
私はこのルーチンを使用して、Web フォームのほとんどの入力をサニタイズします (少し前に書きましたが、改善も求めています)。
function fnSanitizePost($data) //escapes,strips and trims all members of the post array
{
if(is_array($data))
{
$areturn = array();
foreach($data as $skey=>$svalue)
{
$areturn[$skey] = fnSanitizePost($svalue);
}
return $areturn;
}
else
{
if(!is_numeric($data))
{
//with magic quotes on, the input gets escaped twice, which means that we have to strip those slashes. leaving data in your database with slashes in them, is a bad idea
if(get_magic_quotes_gpc()) //gets current configuration setting of magic quotes
{
$data = stripslahes($data);
}
$data = pg_escape_string($data); //escapes a string for insertion into the database
$data = strip_tags($data); //strips HTML and PHP tags from a string
}
$data = trim($data); //trims whitespace from beginning and end of a string
return $data;
}
}
上記のような文字がデータベースに保存されるのを本当に避けたいのですが、消毒ルーチンに正規表現の置換を追加する必要がありますか?
ありがとう、
-
ニコラス