我正在做一个表单验证器(以及其他内容)并且我已经在我的脚本中设置了响应代码,因此我可以使用AJAX ..出于某些奇怪的原因,它会在发生此错误时抛出此错误我执行脚本:
致命错误:调用未定义的函数http_response_code()
我的剧本:
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$email = filter_var(trim($_POST['email'],FILTER_SANITIZE_EMAIL));
$code = trim($_POST['code']);
if (!filter_var($email, FILTER_VALIDATE_EMAIL) OR empty($code)){
http_response_code(400);
echo "Oops! There was a problem with your submission. Try again!";
exit;
}
if(!$conn) die("Something wrong happened" . mysql_error());
if(mysql_query($sql,$conn)){
if(isset($_POST['newsletter'])){
$MailChimp = new MailChimp();
$list_id = '*********';
$user_info = array('email_address' => $email,'status' => 'subscribed');
$result = $MailChimp->post("lists/$list_id/members",$user_info);
if(strpos($MailChimp->getLastError(), 'is already a list member') !== false) echo 'You are already subscribed, smarty pants!';
}
http_response_code(200);
echo "Thank you!";
}
else{
http_response_code(500);
echo "Oops! Something went wrong";
}
if(!mysql_query($sql,$conn)) echo "<p>" . "There seems to be a problem :< ... Please check the info you provided and try again!" . "</p>";
else echo "<p>" . "Much thanks! Very wow :D" . "</p>";
mysql_close($conn);
}
任何人都知道可能发生的事情或更好的方法吗?