Support » Plugin: Akismet Anti-Spam » Commenter's IP on reverse proxy

  • Commneter’s IP is always returned like ‘127.0.0.1’ under the reverse proxy.

    akismet.php line 324:
    $comment['user_ip'] = $_SERVER['REMOTE_ADDR'];

    I want to fix like below.
    pre_comment_user_ip filter is same filter on WordPress core.

    $comment['user_ip'] = apply_filters('pre_comment_user_ip', $_SERVER['REMOTE_ADDR']);

    So, I will able to fix this problem with my custom plugin like below:

    function my_pre_comment_user_ip()
    {
        if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $x_forward_for = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
            $remote_addr = trim($x_forward_for[0]);
        } else {
            $remote_addr = $_SERVER['REMOTE_ADDR'];
        }
        return $remote_addr;
    }
    
    add_filter( 'pre_comment_user_ip', 'my_pre_comment_user_ip' );

    Thanks!

    http://wordpress.org/plugins/akismet/

  • The topic ‘Commenter's IP on reverse proxy’ is closed to new replies.