【问题标题】:PHP Radio Button Secure When Emailing发送电子邮件时 PHP 单选按钮安全
【发布时间】:2018-02-05 06:27:59
【问题描述】:

我一直在试图弄清楚通过电子邮件发送单选按钮和复选框时是否需要去掉(清理?)以及如何去做。

我有一个仅通过电子邮件发送信息的联系表。它不涉及数据库。发送电子邮件时是否需要保护单选按钮和复选框?有可能吗?

我在谷歌上没有找到任何关于在给他们发送电子邮件时保护这些内容的信息。我不断遇到一些答案,说在发送到数据库时绝对应该受到保护。在这里可以找到相同的内容,或者有关如何获取值或动态创建值的问题。所以,我很茫然。

发送电子邮件时,我是否保护单选按钮和复选框?可能吗?必要的?如果是这样,我该怎么做?

这是我的部分代码的样子:

    $firstName = strip_tags($_POST['firstName']);
    $lastName = strip_tags($_POST['lastName']);
    $email = strip_tags($_POST['emailAddress']);
    $telNum = strip_tags($_POST['phoneNumber']);
    $colors= $_POST['eColors'];
    $additionalComments = strip_tags($_POST['additionalComments']);
    $spamField = strip_tags($_POST['sField']);


    <form id="contact-form" action="" method="post">

    <div>
            <input type="text" id="nameFirst" name="firstName" /> 
            <label for="nameFirst" class="nameIcon">
                <span>First Name</span>
            </label>
            <span class="hint">
                <p>Input hint goes here</p>
            </span>
        </div>

        <div>
            <input type="text" id="nameLast" name="lastName" />
            <label for="nameLast" class="nameIcon">
                <span>Last Name</span>
            </label>
            <span class="hint">
                <p>Input hint goes here</p>
            </span>
        </div>

        <div>
            <input type="email" id="eAddy" name="emailAddress" />
            <label for="eAddy" class="emailIcon">
                <span>Contact Email</span>
            </label>
            <span class="hint">
                <p>Input hint goes here</p>
            </span>
        </div>

        <div>
            <input type="tel" id="telNum" name="phoneNumber" />
            <label for="telNum" class="contactIcon">
                <span>Contact Number</span>
            </label>
            <span class="hint">
                <p>Input hint goes here</p>
            </span>
        </div>

        <div>
            <input type="checkbox" id="cbEColors" name="eColors" class="cbSwitch" />
            <label for="cbEColors">Do you expect more color?</label>
        </div>

        <div>
            <textarea id="addComments" name="additionalComments"></textarea>
            <label for="addComments" class="messageIcon">
                <span>Additional Comments</span>
            </label>
            <span class="hint">
                <p>Input hint goes here</p>
            </span>
        </div>

        <input type="text" id="sField" class="col" name="sField" />

        <button id="submit" name="submit" type="submit" value="Submit">Submit</button>

    </form>

【问题讨论】:

    标签: php html checkbox radio-button


    【解决方案1】:

    我遵循一个简单但关键的 PHP 安全规则:从不信任输入值,无论其预期类型或外部验证(例如客户端浏览器验证)如何。

    here 上有一篇很棒的文章。

    希望这会有所帮助:)

    【讨论】:

    • 您知道如何保护单选按钮或复选框吗?我知道一般输入使用strip_tags。 IE strip_tags($_POST['phoneNumber']); 其他两个我该怎么做?另外,是的,这很有帮助,我已经为它添加了书签,所以我拥有它。谢谢。
    • 答案可能会有所不同,具体取决于允许的复选框值。我个人会为该字段定义一个接受值的数组,并执行以下操作: $checkboxValue = (!empty($_POST['checkboxInput']) && in_array($_POST['checkboxInput'], $acceptedValues)) ? $_POST['checkboxInput'] : null;它检查输入是否有值以及该值是否在接受值的数组中。如果满足这些条件,则将 $checkboxValue 分配给发送的值,否则设置为 null。
    • 我刚刚在搜索中找到了。谢谢。
    【解决方案2】:

    首先,正确的术语是经过消毒的。 (你很亲密)

    另外,为了安全起见,我愿意。请记住,人们可以将输入从复选框更改为输入。即使您没有将其提交到数据库,如果有一天您决定提交怎么办?您很可能会忘记这一切,突然间您的生产数据库受到了威胁。

    为了缩短长篇文章,是的。

    【讨论】:

    • 谢谢。这大大减少了我的搜索量。
    猜你喜欢
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 2014-02-01
    • 2013-02-19
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    • 2013-08-06
    相关资源
    最近更新 更多