capturing user's ip address in php contact form
<p>I'm trying to get the user ip address from a php contact form, i have the following code, but i want to know is it valid to use clean_string in this way to email myself the ip address?</p>

<pre><code>&lt;?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.&lt;br /&gt;&lt;br /&gt;";
    echo $error."&lt;br /&gt;&lt;br /&gt;";
    echo "Please go back and fix these errors.&lt;br /&gt;&lt;br /&gt;";
    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");
?&gt;
&lt;script&gt;location.replace('&lt;?php echo $thankyou;?&gt;')&lt;/script&gt;
&lt;?php
}
die();
?&gt;
</code></pre>

<p>Also,</p>

<pre><code>$ip = $_SERVER['HTTP_CLIENT_IP'];
</code></pre>

<p>is on the contact form script page, not the actual form.php which the user enters information on, i think thats where im going wrong right?</p>
