Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 表格确认及;蜜罐-我的代码正确吗?_Javascript_Validation_Honeypot - Fatal编程技术网

Javascript 表格确认及;蜜罐-我的代码正确吗?

Javascript 表格确认及;蜜罐-我的代码正确吗?,javascript,validation,honeypot,Javascript,Validation,Honeypot,到目前为止,我已经成功地使用了下面的表单验证。它有必填字段、电子邮件验证和垃圾邮件蜜罐。然而,我的一个客户得到的是空白表单结果,而实际上表单根本不应该提交。所以也许我没有看到显而易见的东西。我认为这是非常简单的代码。如果我遗漏了什么,谁能快速看一眼并告诉我吗 另一方面,垃圾邮件机器人是否比蜜罐更聪明 这是JS: <script> function verify() { var themessage = "You are required to complete the fol

到目前为止,我已经成功地使用了下面的表单验证。它有必填字段、电子邮件验证和垃圾邮件蜜罐。然而,我的一个客户得到的是空白表单结果,而实际上表单根本不应该提交。所以也许我没有看到显而易见的东西。我认为这是非常简单的代码。如果我遗漏了什么,谁能快速看一眼并告诉我吗

另一方面,垃圾邮件机器人是否比蜜罐更聪明

这是JS:

<script>
function verify() {
    var themessage = "You are required to complete the following fields: ";
    var x=document.form.email.value
    var atpos=x.indexOf("@");
    var dotpos=x.lastIndexOf(".");

    if (document.form.address.value!="") {
        themessage = "You are not human! No form for you!";
    }

    if (document.form.first_name.value=="") {
        themessage = themessage + " - First Name";
    }

    if (document.form.last_name.value=="") {
        themessage = themessage + " - Last Name";
    }

    if (document.form.email.value=="") {
        themessage = themessage + " - E-mail";
    }

    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
        themessage = "You need to enter a valid email address";
    }

    //alert if fields are empty and cancel form submit
    if (themessage == "You are required to complete the following fields: ") {
        document.form.submit();
    }

    else {
        alert(themessage);
        return false;
    }
}
</script>

函数验证(){
var themessage=“您需要填写以下字段:”;
var x=document.form.email.value
var atpos=x.indexOf(“@”);
var dotpos=x.lastIndexOf(“.”);
if(document.form.address.value!=“”){
themessage=“你不是人类!你没有形体!”;
}
if(document.form.first\u name.value==“”){
themessage=themessage+“-名字”;
}
if(document.form.last_name.value==“”){
themessage=themessage+“-姓氏”;
}
if(document.form.email.value==“”){
themessage=themessage+“-E-mail”;
}
如果(atpos)

在字段中填入空格(电子邮件除外)将生成一个看似空的表单结果

您可能只使用表单数据的客户端验证,这是不好的

机器人程序不运行JavaScript,因此它们会忽略您的
verify
函数,只发送纯HTML格式的表单

一般来说,出于安全原因以及用户可能在其浏览器设置中禁用了JavaScript,您应该始终给予服务器端验证更高的优先级


在JavaScript中执行这些类型的验证应该是提高可用性的可选功能,但它不应该实现安全功能(如“蜜罐”).

表单结果都是空白的,包括email字段,这告诉我代码中有些地方不正确,或者机器人现在更聪明了,可以绕过验证。根据我的代码,如果名字和姓氏都是空白,表单就不应该通过,对吗?我说的空白是chr(32)。但是,如果电子邮件也是空白的,我的怀疑是错误的。谢谢你的输入。关于如何在哪里查找有关如何保护表单服务器端的信息,有什么建议吗?互联网上有很多关于这方面的信息,只需搜索“验证输入”。OWASP创建了一个有关于数据验证的章节,等等。
<form name="form" method="post" action="output.php">
    <div id="input">
        <div id="field">First Name:</div>
        <input name="first_name" type="text" id="first_name">
    </div>

    <div id="input">
        <div id="field">Last Name:</div>
        <input name="last_name" type="text" id="last_name">
    </div>

    <div id="input">
        <div id="field">Email:</div>
        <input name="email" type="text" id="email">
    </div>

    <div class="input address"><!-- This is the Honeypot -->
        <div id="field">Address:</div>
        <input name="address" type="text" id="address">
    </div>

    <div id="input">
        <div id="field">Phone:</div>
        <input name="phone" type="text" id="phone">
    </div>

    <div id="input">
        <div id="field3">Comments:</div>
        <textarea name="comments" id="comments"></textarea>
    </div>

    <input type="button" value="Submit" onclick="verify();">
</form>