drvntaomy06331839 2014-04-12 23:22
浏览 50
已采纳

PHP filter_input验证并清理

I'm coding a contact form and I want to validate and sanitize user input using filter_input The problem is that because I use it for every POST variable shall I do a validate then sanitize or what? my suggestion is as follows:

if (!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) {
exit ();
} else {
$email  = $_POST['email'];
}

is this OK or I must re-sanitize the $_POST['email']

Thanks

  • 写回答

2条回答 默认 最新

  • dongzhijing8202 2014-04-12 23:24
    关注

    Try this:

    if ( !$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) {
        exit();
    }
    
    echo $email
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?