[英]PHP Form processing redirects with POST data in url
在第一次提交時,這使用戶返回索引,而POST數據仍在URL中。 現在,在第二次提交的URL中包含數據時,它隨后返回錯誤或處理郵件。 我不確定到底是什么原因造成的。
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$company = $_POST['company'];
$project = $_POST['project'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
unset($_POST);
//Validate first
if(empty($name)||empty($email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($email))
{
echo "Bad email value!";
exit;
}
$email_from = 'wevans.evansweb@gmail.com';
$email_subject = "New Contact Request";
$email_body = "You have received a new message from $name.\n
email: $email\n
company: $company\n
project: $project\n
phone: $phone\n
message: $message\n";
$to = 'wevans.evansweb@gmail.com';
$headers = "From: $email_from \r\n";
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: index.html');
// Function to validate against any email injection attempts
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;
}
}
?>
您確定在表單的HTML中使用method="post"
嗎?
<FORM action="someURL.php" method="post">
據我所知,當method
為get
,URL中會顯示表單值,因為您在PHP中使用$_POST
,因此無法按您的情況為您服務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.