Adding Visitor IP and Current Page to “Contact Form 7″ Wordpress Plugin
Make sure to get FREE SEO link packages Vince's Links
I’ve loved using the Contact Form 7 Wordpress Plugin so far, but it was missing two VITAL features:
I was unable to send the visitors IP address with the form submission, and I was unable to tell which exact page the form submission came from if I was using the form on more than one page.
Here is a fix for both of those little short falls:
Edit the plugin - You can do this through the wordpress plugin editor http://YOUR-DOMAIN-NAME/wp-admin/plugin-editor.php
Paste the following code just above the last line of code - The last line of code is simply “?>”
function curPageURL() {
$pageURL = ‘http’;
if ($_SERVER["HTTPS"] == “on”) {$pageURL .= “s”;}
$pageURL .= “://”;
if ($_SERVER["SERVER_PORT"] != “80″) {
$pageURL .= $_SERVER["SERVER_NAME"].”:”.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
Next search for this line of code which should appear directly in the middle of the plugin:
$form .= ‘<div style=”display: none;”>’;
Below this line, paste the following code.
// Addition By: Vince Samios, http://vincesamios.com
$curpageurl = curpageurl();
$visip=$_SERVER['REMOTE_ADDR'];
$form .= ‘<input type=”hidden” name=”page-url” value=”‘ . $curpageurl . ‘” />’;
$form .= ‘<input type=”hidden” name=”visitor-ip” value=”‘ . $visip . ‘” />’;
Now you can reference these values in the email like you would any other form field. Example below
Page: [page-url]
IP: [visitor-ip]
Another useful piece of code by “Travis” is for adding the contact form in PHP - this is useful if you would like to include it in the theme.
echo apply_filters(’the_content’,’
‘);
Update:
Added time and date of submission - Add this in the same place as the Visitor IP and Current Page additions.
date_default_timezone_set(’GMT’);
$timedate = date(’l jS \of F Y h:i:s A’);
$form .= ‘<input type=”hidden” name=”time-date” value=”‘ . $timedate . ‘” />’;
You can reference the time and date in the contact enquiry email by using:
[time-date]
Incoming seo search terms:
Posted: March 20th, 2009 under Internet Marketing.
Tags: Contact Form 7, IP Address, Page URL, Theme, Wordpress Plugin
Comments
Comment from admin
Time April 3, 2009 at 5:34 am
I’m not using contact form 7 on my blog, just on various money sites. Since posting, I’ve also added a time stamp to contact form 7 so I can see the exact time and date of submission.
Comment from giantmonster
Time April 5, 2009 at 3:03 pm
darn. i definitely want these features (IP & time stamp) & followed your instructions. but i just couldn’t get this code to work. plug-in would deactivate once the code was inserted. tried it by deactivating the plug-in first & then re-activating it. no dice. kept getting this error message:
Parse error: syntax error, unexpected T_STRING in /–/–/–/wp-content/plugins/contact-form-7/wp-contact-form-7.php on line 919
and
Parse error: syntax error, unexpected ‘:’ in /–/–/–/wp-content/plugins/contact-form-7/wp-contact-form-7.php on line 1810
any tips on getting it to work would be most appreciated. thanks!
Comment from admin
Time April 6, 2009 at 9:35 am
Hmmm… probably a problem with copy/pasting the code…
Try pasting the code into notepad, the re-copy pasting it into the plugin. This sometimes helps sanitize the text formatting (but come to think of it, sounds unlikely in this case)
Also ensure you are pasting it in at the correct spot.
You don’t need to de-activate the plugin to add the code.
Comment from Todd
Time July 27, 2009 at 10:22 pm
I’m using version 2.2.6 and “$form .= ‘’;” is no where to be found on the code.
Pingback from Contact Form 7 IP Address
Time October 21, 2009 at 5:41 am
[...] income strategy or follow me on twitterOh, and come back soon! :-)In a previous post I wrote about adding an IP address field into Contact Form 7 [...]
Comment from tim
Time January 19, 2010 at 7:32 pm
You can also add this into the message body part of Contact form 7 and it will send the ip address.
[wpcf7.remote_ip]
It’s probably a new feature since this article was written but this article still ranks for the subject in google so it would be good for people to know.
I got this info from the wordpress site.
Comment from Steve
Time July 20, 2010 at 1:40 pm
This just isn’t working for me. Which .php file in the plugin are we editing here?
Comment from seattle seo
Time October 25, 2010 at 5:21 pm
I am going to adapt the code to work with the current version, you can check it out at my site




SEO Guide 2011
Comment from Bruce
Time March 30, 2009 at 10:27 pm
Thanks for the snippet Vince,
I was searching your (blog) site for a contact form. I’m looking for an example, but I don’t see any.