php - 安全电子邮件表单、 header 注入(inject)查询

标签 php email header security code-injection

我正在使用以下内容来清理联系表单中的输入:

<?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/

相关文章:

python - 在不丢失表单数据的情况下,在 Pylons 中重定向请求的首选方法是什么?

php - mysqli_fetch_assoc()需要参数/调用成员函数bind_param()错误。如何获取并修复实际的mysql错误?

php - 使用 PHP 从 MySQL 数据库中仅检索今天的记录

java - 如何配置 spring-boot 通过 sendGrid 发送邮件?

java - 需要有关使用 java 发送短信的帮助

html - 制作一个所有内容垂直对齐的 CSS 标题

javascript - linux php 执行() msg​​get :Permission Denied

php - 如何使用 Symfony2 翻译器翻译 twig 模板中的连接字符串

email - 在 webapp 中处理未送达的电子邮件

html - 如何在一个div中对齐2个div?