Report IP option in contact_form!

Talk about new features for CMSMS and modules.
Post Reply
johnqpublic

Report IP option in contact_form!

Post by johnqpublic »

Hi,

It would be great if the contact form had an option to turn on IP address reporting when people fill out the contact form.  I know I need to add something like this in the form, but I keep breaking it no matter how hard I try!  My PHP skills are rather weak!



Thanks for listening.

John Q. Public
geoffb

Re: Report IP option in contact_form!

Post by geoffb »

This wasn't too difficult to implement. On a 0.11.1 system, make the following edits to the plugins/function.contact_form.php file:

At about line 37 (immediately after "if (!empty($_POST['message'])) $message = trim($_POST['message']);") add these two lines:

Code: Select all

	$env_report = '';
	if (!empty($_POST['env_report'])) $message .= "\n\nenv_report == " . trim($_POST['env_report']);
then, at about line 75 (immediately before ), add this line:

Code: Select all

	<input type="hidden" name="env_report" value="<?php echo $_SERVER["REMOTE_ADDR"] . ', ' . $_SERVER["HTTP_USER_AGENT"] ?>">

This will add a line to the bottom of the email message that says "env_report == , "

It doesn't give you the option to choose what things you want included, that would take a little bit more playing around. (I only solved this problem to avoid doing actual work of my own for a few minutes!!!) :D ;D :D

I hope this helps,

GB
geoffb

Re: Report IP option in contact_form!

Post by geoffb »

Actually, in hindsight, that was a pretty dumb solution. I guess I just fell in to using the approach 'cos that's what your question asked for. In fact, making those values something that the client submits makes them open to spoofing. Instead, do this...


At about line 37 (immediately after "if (!empty($_POST['message'])) $message = trim($_POST['message']);")" add these two lines:

Code: Select all

	$env_report = $_SERVER["REMOTE_ADDR"] . ', ' . $_SERVER["HTTP_USER_AGENT"];
	$message .= "\n\nenv_report == " . $env_report;
Add nothing to the ... section. The other notes re not doing quite what you asked for still apply, this still applies to an 0.11.1 system, and I still haven't got back to doing my actual work!

Enjoy!

GB
johnqpublic

Re: Report IP option in contact_form!

Post by johnqpublic »

Thanks for not doing your work and taking the time to help me out!  ;D

I'm using 0.11.2 now, not 0.11.1 since it had the contact form injection problems, but that didn't stop me from trying out your code.  It seems to work just fine... test messages show the IP and other variables great... so I hope I didn't break anything I'm not aware of.

Again, thanks for the help.  It's appreciated.



A email address to send to must be specified in order to use this plugin.';
return;
}else{
$to = $params['email'];
}

$style = true;
if (!empty($params['style']))$style = $params['style'];

$name=$email=$subject=$message = '';
if($_SERVER['REQUEST_METHOD']=='POST'){
if (!empty($_POST['name'])) $name = cfSanitize($_POST['name']);
if (!empty($_POST['email'])) $email = cfSanitize($_POST['email']);
if (!empty($_POST['subject'])) $subject = cfSanitize($_POST['subject']);
if (!empty($_POST['message'])) $message = cfSanitize($_POST['message']);
$env_report = $_SERVER["REMOTE_ADDR"] . ', ' . $_SERVER["HTTP_USER_AGENT"];
$message .= "\n\nenv_report == " . $env_report;

$extra = "From: $name \r\nReply-To: $email\r\n";
echo '';

if (empty($name)) {
echo 'Please Enter Your Name.';
}elseif (empty($email)) {
echo 'Please Enter Your Email Address.';
}elseif (empty($subject)) {
echo 'Please Enter a Subject.';
}elseif (empty($message)) {
echo 'Please Enter a Message.';
}elseif (!validEmail($email)) {
echo 'Your Email Address is Not Valid.';
}elseif (@mail($to, $subject, $message, $extra)){
echo "Your message was successfully sent.";
return;
}else{
echo 'Sorry, the message was not sent. The server may be down!';
return;
}

echo '';
}
?>

" method="post" name="contactForm">
Your Name:" size="50" />
Your Email Address:" size="50" />
Subject:" size="50" />
Message:>




What does this do?
Display's a contact form.  This can be used to allow others to send an email message to the address specified.
How do I use it?
Just insert the tag into your template/page like: {contact_form email="yourname@yourdomain.com"}

If you would like to send an email to multiple adresses, seperate each address with a comma.
What parameters does it take?

email - The email address that the message will be sent to.
(optional)style - true/false, use the predefined styles. Default is true.



Author: Brett Batie<brett-cms@classicwebdevelopment.com>
Version: 1.1

Change History:
None

Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: Report IP option in contact_form!

Post by Ted »

I'm going to add this into the next release.  Nice work.
Post Reply

Return to “Feature ideas”