請我需要您的幫助。如何在頁面刷新時防止空白張貼
我有一個在線表格(http://mmg2015.org/participationform.php),它將數據發佈到後端數據庫。它的作品非常好。但我決定添加一個電子郵件代碼,如下所示,這樣當表單提交時,表單內容的副本將被髮送到電子郵箱,以便管理員能夠確認並作出迴應。
現在,因爲我添加了電子郵件代碼,所以當頁面/表單刷新時,表單會向我的電子郵箱中留下空白字段。由於沒有內容,但我的電子郵件不斷收到表單中的空電子郵件,因此沒有任何內容發佈到數據庫。
任何人都可以幫我確定爲什麼它張貼空白。
<?php
$emailSubject = 'A new application for participation!';
$webMaster = '[email protected]';
// $email and $message are the data that is being
// posted to this page from our html contact form
$nameoforganisation = $_POST['nameoforganisation'] ;
$sector = $_POST['sector'] ;
$address = $_POST['address'] ;
$email = $_POST['p1email'] ;
$p1name = $_POST['p1name'] ;
$p1phone = $_POST['p1phone'] ;
$p1designation = $_POST['p1designation'] ;
$p1email = $_POST['p1email'] ;
$p2name = $_POST['p2name'] ;
$p2phone = $_POST['p2phone'] ;
$p2designation = $_POST['p2designation'] ;
$p2email = $_POST['p2email'] ;
$signature = $_POST['signature'] ;
$body = <<<EOD
<br><hr><br>
Name of Organisation: $nameoforganisation <br>
Sector: $sector <br>
Address: $address <br>
First Participants Details:<br>
Name: $p1name <br>
Phone: $p1phone <br>
Designation: $p1designation <br>
Email: $p1email <br>
Second Participants Details:<br>
Name: $p2name <br>
Phone: $p2phone <br>
Designation: $p2designation <br>
Email: $p2email <br>
Signature: $signature <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
?>
我用大量的感謝
邁克
您的代碼易受頭部注入影響。 – PeeHaa
那麼http://en.wikipedia.org/wiki/Post/Redirect/Get呢? – rkosegi
@PeeHaa:請問我該如何處理?你能給我一個關於如何處理標題注入的提示 –