PHP表单处理使用url中的POST数据重定向
在第一次提交时,这会将用户返回到索引,而帖子数据仍在URL中。在第二次提交url中的数据时,它会返回错误或处理邮件。我不确定到底是什么原因造成了这种情况PHP表单处理使用url中的POST数据重定向,php,Php,在第一次提交时,这会将用户返回到索引,而帖子数据仍在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['n
<?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中使用了
方法=“post”
<FORM action="someURL.php" method="post">
据我所知,当方法
为get
时,表单值会显示在URL中,这在您的情况下不会像预期的那样为您服务,因为您在PHP中使用的是$\u POST