PDA

View Full Version : Capturing IP on form submission



jen2swt0509
10-10-2011, 02:39 PM
I know this has probably been asked several times, but I can not get the IP and host info to submit on a form submission. Here is my code. Can someone please let me know what I'm missing?


<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_city = $_POST['cf_city'];
$field_number = $_POST['cf_number'];
$field_trade = $_POST['cf_drop_down'];
$field_yrstrade = $_POST['cf_trade'];
$field_working = $_POST['cf_working'];
$field_tools = $_POST['cf_tools'];
$field_request = $_POST['cf_request'];


$mail_to = '[email protected]';
$subject = 'Employment Inquiry from '.$field_name;

$body_message .= 'Name: '.$field_name."\n";
$body_message .= 'Email: '.$field_email."\n";
$body_message .= 'City and State: '.$field_city."\n";
$body_message .= 'Phone Number: '.$field_number."\n";
$body_message .= 'Trade: '.$field_trade."\n";
$body_message .= 'Years in Trade: '.$field_yrstrade."\n";
$body_message .= 'Currently working: '.$field_working."\n";
$body_message .= 'Do you have your own Tools: '.$field_tools."\n";
$body_message .= 'Issues with background check and drug Test?: '.$field_request."\n";


$headers = 'From: '.$cf_email."\r\n";
$headers .= 'Reply-To: '.$cf_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

// if the env_report option is on: get eviromental variables
if ($env_report) {
$env_report = ereg_replace( " +", "", $env_report);
$env_reports = split(",",$env_report);
$content .= "\n------ eviromental variables ------\n";
for ($i=0;$i<count($env_reports);$i++) {
$string = trim($env_reports[$i]);
if ($env_reports[$i] == "REMOTE_HOST")
$content .= "REMOTE HOST: ".$_SERVER['REMOTE_HOST'] ."\n";
if ($env_reports[$i] == "REMOTE_USER")
$content .= "REMOTE USER: ". $_SERVER ['REMOTE_USER'] ."\n";
if ($env_reports[$i] == "REMOTE_ADDR")
$content .= "REMOTE ADDR: ". $_SERVER ['REMOTE_ADDR'] ."\n";
if ($env_reports[$i] == "HTTP_USER_AGENT")
$content .= "BROWSER: ". $_SERVER ['HTTP_USER_AGENT'] ."\n";
}
}



if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'careers.php';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to [email protected]');
window.location = 'contact_page.html';
</script>
<?php
}
?>

And my form


<form action="careermail.php" method="post">
Your name<br>
<input type="text" name="cf_name"><br><br>
Your Email<br>
<input type="text" name="cf_email"><br><br>
City and State you reside in<br>
<input type="text" name="cf_city"><br><br>
What is the best number to reach you?<br>
<input type="text" name="cf_number"><br><br>
What is your trade?<br>
<select size="1" name="cf_drop_down"><br><br>
<option></option>
<option>Carpentry</option>
<option>Concrete</option>
<option>Electrician</option>
<option>Finishing</option>
<option>General Labor</option>
<option>Painter</option>
<option>Plumbing</option> </select><br><br>

How many years experience do you have in your trade? <br>
<input type="text" name="cf_trade"><br><br>

Are you currently working?<br>
<input type="text" name="cf_working"><br><br>
Do you have your own set of tools?<br>
<input type="text" name="cf_tools"><br><br>
In order to work for us you must be able to pass a background check, drug test and be at least 18 yrs of age. Do you have you have any issues with these requests?<br>
<input type="text" name="cf_request"><br><br>


<input type=hidden name="env_report" value="REMOTE_HOST,HTTP_USER_AGENT,REMOTE_USER,REM OTE_ADDR">






<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>

Rowsdower!
10-10-2011, 02:48 PM
Where do you populate the $env_report variable? I don't see it in the code you have provided.

jen2swt0509
10-10-2011, 03:09 PM
Where do you populate the $env_report variable? I don't see it in the code you have provided.

You mean in the form? It's there...unless I have it coded it funky. I'm still learning PHP...

jen2swt0509
10-10-2011, 03:29 PM
NEvermind, I figured it out :) I just simply used a much simpler code...lol. Thanks for the help