簡體   English   中英

PHP聯系表單在所有字段中提交1

[英]PHP contact form submitting 1's in all fields

我最近為我的自由客戶開發了一個網站,在他們的網站中有一個聯系表和一個估算請求表。

每天一次,兩種表格都將提交並通過電子郵件發送到指定的電子郵件地址。 但是,提交的表單顯然不是來自真實用戶的,這是因為所有字段都包含數字1。例如,名稱字段將為Name:1,而地址字段將為Address:1。 對於所有輸入文本字段,甚至是單選和復選框表單字段,都重復數字1。

以下是我用來提交“估算請求”表單的PHP文件的副本。

<?
$subject="Associated Sennott Contractors Request For Estimate From:".$_GET['firstname'];
$headers= "From: ".$_GET['email']."\n";
$headers.='Content-type: text/html; charset=iso-8859-1';
mail("email@gmail.com", $subject,  "
    <html>
        <head>
            <title>Associated Sennott Contractors Request For Estimate</title>
    </head>
<body>
    <p><strong>Associated Sennott Contractors Request For Estimate</strong></p>
    <p>
        First Name: ".$_GET['firstname']." <br />
        Last Name: ".$_GET['lastname']." <br />
        Company Name: ".$_GET['company']." <br />
        Address 1: ".$_GET['address1']." <br />
        Address 2: ".$_GET['address2']." <br />
        City: ".$_GET['city']." <br />
        State: ".$_GET['state']." <br />
        Zip: ".$_GET['zip']." <br />
        Phone: ".$_GET['phone']." <br />
        Fax: ".$_GET['fax']." <br />
        Email: ".$_GET['email']." <br /><br />

        <strong>Property Type:</strong><br />
        Residential Single Family: ".$_GET['singlefamily']." <br />
        Residential Multi-Family: ".$_GET['multifamily']." <br />
        Residential Out-Building : ".$_GET['outbuilding']." <br />
        Commercial Office: ".$_GET['commercial']." <br />
        Retail Store: ".$_GET['retail']." <br />
        Restaurant: ".$_GET['restaurant']." <br />
        Industrial Building: ".$_GET['industrial']." <br /><br />

        <strong>Requested Services:</strong><br />
        Fire, Water or Wind Damage Restoration: ".$_GET['restoration']." <br />
        Scope of Loss Estimate to Insurance Company: ".$_GET['scope']." <br />
        Smoke Odor Remediation: ".$_GET['smoke']." <br />
        Exterior Remodeling or Siding: ".$_GET['exterior']." <br />
        Interior Remodeling: ".$_GET['interior']." <br />
        Hardwood and Laminate Flooring: ".$_GET['flooring']." <br />
        Finish Carpentry: ".$_GET['carpentry']." <br />
        Demolition and Debris Removal: ".$_GET['demo']." <br />
        Exterior Decks, Patios and Fencing: ".$_GET['patio']." <br />
        Other: ".$_GET['other']." <br /><br />

        <strong>Additional Information:</strong><br />
        Message: ".$_GET['info']."
    </p>  
</body>
</html>" , $headers);
header( 'Location: thankyou.html' ) ;
?>

您也可以通過以下鏈接查看PHP代碼: http : //sennottcontractors.com/home-repair-estimate/quote-code.html

然后,您可以在下面查看實際表單的HTML代碼:

<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Request An Estimate Form</title>
<script type="text/javascript">
function formSubmit()
{
document.getElementById("estimate-form").submit();
}
</script>

</head>
<body>
<fieldset>
<legend><h3>Request a Home Restoration Estimate</h3></legend>
    <form id="estimate-form" name="estimate-form" target="_parent" method="get" action="quote.php" onsubmit='return formValidator()'>
        <p><strong>Contact Information</strong></p>
            <p>First Name: *<br />
            <input type="text" size="40" name="firstname" id="firstname" /></p>
            <p>Last Name: *<br />
            <input type="text" size="40" name="lastname" id="lastname" /></p>
            <p>Company Name:<br />
            <input type="text" size="40" name="company" id="company" /></p>
            <p>Address 1: *<br />
            <input type="text" size="40" name="address1" id="address1" /></p>
            <p>Address 2:<br />
            <input type="text" size="40" name="address2" id="address2" /></p>
            <p>City: *<br />
            <input type="text" size="30" name="city" id="city" /></p>
            <p>State: *<br />
            <input type="text" size="5" name="state" id="state" /></p>
            <p>Zip: *<br />
            <input type="text" size="10" name="zip" id="zip" /></p>
            <p>Phone: *<br />
            <input type="text" size="20" name="phone" id="phone" /></p>
            <p>Fax:<br />
            <input type="text" size="20" name="fax" id="fax" /></p>
            <p>Email: *<br />
            <input type="text" size="40" name="email" id="email" /></p>
        <br />
        <p><strong>Property Type</strong> *</p>
            <p><input type="checkbox" name="singlefamily" id="singlefamily"/> Residential Single Family</p>
            <p><input type="checkbox" name="multifamily" id="multifamily"/> Residential Multi-Family <em>(Condominium, apartment, town house, ect)</em></p>
            <p><input type="checkbox" name="outbuilding" id="outbuilding"/> Residential Out-Building <em>(Garage, shed, ect)</em></p>
            <p><input type="checkbox" name="commercial" id="commercial"/> Commercial Office</p>
            <p><input type="checkbox" name="retail" id="retail"/> Retail Store</p>
            <p><input type="checkbox" name="restaurant" id="restaurant"/> Restaurant</p>
            <p><input type="checkbox" name="industrial" id="industrial"/> Industrial Building</p>
        <br />
        <p><strong>Requested Services</strong> *</p>
            <p><input type="checkbox" name="restoration" id="restoration"/> Fire, Water or Wind Damage Restoration</p>
            <p><input type="checkbox" name="scope" id="scope"/> Scope of Loss Estimate to Insurance Company</p>
            <p><input type="checkbox" name="smoke" id="smoke"/> Smoke Odor Remediation</p>
            <p><input type="checkbox" name="exterior" id="exterior"/> Exterior Remodeling or Siding</p>
            <p><input type="checkbox" name="interior" id="interior"/> Interior Remodeling</p>
            <p><input type="checkbox" name="flooring" id="flooring"/> Hardwood and Laminate Flooring</p>
            <p><input type="checkbox" name="carpentry" id="carpentry"/> Finish Carpentry</p>
            <p><input type="checkbox" name="demo" id="demo"/> Demolition and Debris Removal</p>
            <p><input type="checkbox" name="patio" id="patio"/> Exterior Decks, Patios and Fencing</p>
            <p><input type="checkbox" name="other" id="other"/> Other</p>
        <br />
    <p><strong>Additional Information</strong><br />
    Please provide any information regarding details of your home restoration project or additional information to your requested services.</p>
    <p><textarea rows="10" cols="65" id="info" name="info"></textarea></p>
    <button type="submit" id="submit" onclick="formSubmit()">Submit</button>
    </form>
    <p>* Required Fields</p>
</fieldset>
</body>
</html>

您可以通過以下鏈接查看使用上面提到的PHP文件和代碼的“請求估算”表單: http : //sennottcontractors.com/home-repair-estimate/index.html

同樣,每天都提交一次“請求估算”表單和“聯系表單”,每個表單字段中的數字均為1。

我的猜測是這可能是PHP文件本身的問題,或者可能是托管網站的服務器端的問題。

請幫忙!!!

您的表格在技術上沒有任何問題。 您自己說了問題的原因:“ ...提交的表格顯然不是來自真實用戶的……”。 因此,解決方案是使您的表單成為反僵屍程序。 有關如何操作的信息,請在專業版網站管理員網站上看到此問題: 使您的網站成為反機器人程序?

此問題的一部分是您需要使用表單隨機數或“令牌”。

Form.php

<?php
session_start();

$_SESSION['token'] = md5(mt_rand() . unique_id('form', TRUE));

...

?>
<form>
<input type="hidden" value="<?php print $_SESSION['token']; ">
...
</form>

process.php

<?php
session_start();

if($_SESSION['token'] !== $_POST['token'])
{
    die('They did not load the form!');
}

...

(validation)

...

$db->insert($record);

您沒有進行任何驗證。 你能指望什么?

任何人都可以抓住表單字段,創建URL(因為您使用的是GET而不是POST),然后在需要時立即將其提交。 您可能遇到的是一個機器人,試圖弄清楚它是否可以劫持您的表單以將電子郵件發送到想要發送的地方。

您應該做的是切換到使用POST並檢查$_SERVER['HTTP_REFERER']變量,以確保它來自表單(至少)。 您也可以使用CAPTCHA,但是這些正變得越來越不可靠。 您可以更進一步,並使用驗證類為每個字段設置規則,並允許每個字段中包含哪種數據。

表單易於操作,因此,如果您希望表單提交具有任何完整性,則應該在服務器端進行驗證。 客戶端驗證不會受到損害,而只是將其用於用戶體驗目的,而不是確保數據完整性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM