开发者

how to implement FILTER_SANITIZE_SPECIAL_CHARS

here's what I've got so far - i really need to ban any tags from being entered as it's like a guestbook, but this doesn't seem to work:

<?php

$txt = $_POST['txt'];

//the data

$data = "
$txt";

//my attempt to implement a filter

var_dump(filter_var($data,FILTER_SANITIZE_SPECIAL_CHARS));

//open the file and choose the mode

$fh = fopen("user开发者_开发问答s.txt", "a");

fwrite($fh, $data);


//close the file

fclose($fh);

header('Location: http://www.google.com/');
?>


You need to assign the returned value of filter_var

$data = filter_var($data,FILTER_SANITIZE_SPECIAL_CHARS);

filter_var can return FALSE if the filter fails. So, to be complete, you really should do something like:

$filtered_data = filter_var($data,FILTER_SANITIZE_SPECIAL_CHARS);
if($filtered_data !== FALSE) {
  //write $filtered_data
} else {
  //handle error
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜