Contact Form 7 IP Address, Date/Time and Page URL

In a previous post I wrote about adding an IP address field into Contact Form 7 1.9.3

Since then there have been major updates to Contact Form 7, which renders the initial how-to inaccurate.

Luckily – in recent updates Contact Form 7 has added a new tag [wpcf7.remote_ip] which replaces the Adding IP part of my tutorial.

Two functions which haven’t been added and which now no-longer work with my old how-to are adding date and time to Contact Form 7, and adding the Source Page into Contact Form 7.

The function for adding the source page is still the same:

function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
} else {
return $pageURL;

But this time, add it to the bottom of the includes/classes.php file, before the very last “?>”

Next, in the same file (includes/classes.php) search for this line:

$enctype = apply_filters( 'wpcf7_form_enctype', '' );

Directly below this line, add the following code:

$curpageurl = curpageurl();
$timedate = date('l jS \of F Y h:i:s A');

Now search for this line:

. esc_attr( WPCF7_VERSION ) . '" />' . "\n";

Below which you need to add a line and insert the following code:

$form .= '<input type="hidden" name="time-date" value="' . $timedate . '" />';
$form .= '<input type="hidden" name="page-url" value="' . $curpageurl . '" />';

The next step – actually sending those values with the form, is still a mystery…

If you check the form code after making these changes you can see the source page and time/date variables being displayed… but they don’t send with the email…

If you’ve worked it out, please comment below.

9 thoughts on “Contact Form 7 IP Address, Date/Time and Page URL

  1. vance on

    I never worked this out did you get to the bottom of it Vince?

  2. Chris on

    Does this code display the user ip address on the form? Or is it just for displaying in the email?

  3. Only within the email.

    Contact Form 7 has been updated a lot since I wrote this post, but portions are still valid.

  4. Thanks Vince. Do you know if there is a easy way to display the visitors IP address on the form? I’ve been searching the web for a solution but have not see anything.

  5. hello , to send the url code with mail ,

    you can give :
    url : [page-url]
    in the mail configurator.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>