PHP の連絡先フォームからユーザーの IP アドレスを取得しようとしています。次のコードがありますが、この方法で clean_string を使用して IP アドレスをメールで送信することは有効ですか?
<?php
session_start();
if(isset($_POST['fullname'])) {
include 'freecontact2formsettings.php';
function died($error) {
echo "Sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['fullname']) ||
!isset($_POST['Address1']) ||
!isset($_POST['city']) ||
!isset($_POST['Postcode']) ||
!isset($_POST['contactnum']) ||
!isset($_POST['emailaddress'])
) {
died('Sorry, there appears to be a problem with your form submission.');
}
$ip = $_SERVER['HTTP_CLIENT_IP'];
$ansb0_from = $_POST['fullname']; // required
$ansb1_from = $_POST['Address1']; // required
$ansb3_from = $_POST['city']; // required
$ansb4_from = $_POST['Postcode']; // required
$ansb5_from = $_POST['contactnum']; // required
$ansb6_from = $_POST['emailaddress']; // required
$error_message = "";
$email_message = "PHP CONTACT FORM:\r\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:");
return str_replace($bad,"",$string);
}
$email_message .= "Forename: ".clean_string($ansb0_from)."\r\n";
$email_message .= "Address 1: ".clean_string($ansb1_from)."\r\n";
$email_message .= "City: ".clean_string($ansb3_from)."\r\n";
$email_message .= "Postcode: ".clean_string($ansb4_from)."\r\n";
$email_message .= "Contact Number: ".clean_string($ansb5_from)."\r\n";
$email_message .= "Email Address: ".clean_string($ansb6_from)."\r\n";
$email_message .="IP Address: ".clean_string($ip)."\n\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>
また、
$ip = $_SERVER['HTTP_CLIENT_IP'];
ユーザーが情報を入力する実際のform.phpではなく、連絡フォームのスクリプトページにあります。どこが間違っていると思いますか?