我正在使用以下内容来清理联系表单中的输入:
<?php
$name = strip_tags(stripslashes($_POST['name']));
//this is repeated for several other fields, then:
if(isInjected($name)) { die(); }
/* see isInjected function below */
// send the mail
?>
我正在使用这个功能:
<?php
/* function from http://phpsense.com/php/php-mail.html */
function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}
?>
这足以清理我的联系表单吗?
谢谢。
最佳答案
附带说明一下,代码有点臃肿。它可以很容易地修剪:
/* function from http://phpsense.com/php/php-mail.html */
function isInjected($str) {
$inject = "/(\r|\t|%0A|%0D|%08|%09)+/i";
return (preg_match($inject, $str) > 0);
}
关于php - 安全电子邮件表单、 header 注入(inject)查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1826044/