Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter mykm47

    (@mykm47)

    I think I have a solution. Go to the plugin editor and navigate to the following file:

    contact-form-7/includes/submission.php

    At around Line 134, you will find the following code

    ‘remote_ip’ => isset( $_SERVER[‘REMOTE_ADDR‘] )
    ? preg_replace( ‘/[^0-9a-f.:, ]/’, ”, $_SERVER[‘REMOTE_ADDR‘] ): ”,

    Replace “REMOTE_ADDR” (in bold above) with the following:

    HTTP_X_FORWARDED_FOR

    When you save it, it should start showing the right IP. Worked for me.

    Hi, mine didn’t work, i have:
    `
    $this->meta = array(
    ‘remote_ip’ => $this->get_remote_ip_addr(),
    ‘user_agent’ => isset( $_SERVER[‘HTTP_X_FORWARDED_FOR’] )
    ? substr( $_SERVER[‘HTTP_X_FORWARDED_FOR’], 0, 254 ) : ”,
    ‘url’ => preg_replace( ‘%(?<!:|/)/.*$%’, ”,
    untrailingslashit( home_url() ) ) . wpcf7_get_request_uri(),
    ‘timestamp’ => current_time( ‘timestamp’ ),
    ‘unit_tag’ =>
    isset( $_POST[‘_wpcf7_unit_tag’] ) ? $_POST[‘_wpcf7_unit_tag’] : ”,
    );

    Is there something wrong on this?

    thank you.

    Thread Starter mykm47

    (@mykm47)

    Hi,

    I think the code for this form has been updated since I first found the solution a year ago, so the fix is a little different now. First you will probably need to restore the section that you edited:

    $this->meta = array(
    ‘remote_ip’ => $this->get_remote_ip_addr(),
    ‘user_agent’ => isset( $_SERVER[‘HTTP_USER_AGENT’] )
    ? substr( $_SERVER[‘HTTP_USER_AGENT’], 0, 254 ) : ”,
    ‘url’ => preg_replace( ‘%(?<!:|/)/.*$%’, ”,
    untrailingslashit( home_url() ) ) . wpcf7_get_request_uri(),
    ‘timestamp’ => current_time( ‘timestamp’ ),
    ‘unit_tag’ =>
    isset( $_POST[‘_wpcf7_unit_tag’] ) ? $_POST[‘_wpcf7_unit_tag’] : ”,
    );

    Next, go to this section below, and make sure it looks like this (changes are in bold):

    private function get_remote_ip_addr() {
    if ( isset( $_SERVER[‘HTTP_X_FORWARDED_FOR‘] )
    && WP_Http::is_ip_address( $_SERVER[‘HTTP_X_FORWARDED_FOR‘] ) ) {
    return $_SERVER[‘HTTP_X_FORWARDED_FOR‘];
    }

    That should work. Let me know if you want more help.

    Great, this works perfectly now. Thank you @mykm47.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Remote IP incorrect – shows as our site's host IP’ is closed to new replies.