WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
[_remote_ip] gives me the server ip? (6 posts)

  1. Ov3rfly
    Member
    Posted 1 year ago #

  2. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 1 year ago #

    I'm not sure what you meant. Why issue?

  3. Ov3rfly
    Member
    Posted 1 year ago #

    Sorry for unclear description.

    [_remote_ip] gives me the ip of my webserver, I expected the ip of the user who fills in the form.

  4. Ov3rfly
    Member
    Posted 1 year ago #

    Took a look at the module in special-mail-tags.php

    There $_SERVER['REMOTE_ADDR'] is used. This can cause the described issue, it returns an internal proxy-ip of the provider (actually not my webserver) in my case. See e.g. here.

    Possible replacement for current [_remote_ip] handling:

    if ( '_remote_ip' == $name ) {
    	$_ip_addr = $_SERVER['REMOTE_ADDR'];
    	if ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $_SERVER ) )
    		$_ip_addr = array_pop( explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
    	$output = preg_replace( '/[^0-9a-f.:, ]/', '', $_ip_addr );
    }

    Added also another field [_remote_host] which returns the hostname, if possible, otherwise the ip:

    elseif ( '_remote_host' == $name ) {
    	$_ip_addr = $_SERVER['REMOTE_ADDR'];
    	if ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $_SERVER ) )
    		$_ip_addr = array_pop( explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
    	$output = @gethostbyaddr( $_ip_addr );
    }

    Example mail-tags: IP: [_remote_host] ([_remote_ip])
    Example result: IP: some.provider.domain.net (xx.xxx.xxx.xx)

    Feel free to use the code. Thanks for your great plugin!

  5. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 1 year ago #

    That makes sense. Thank you.

  6. Ov3rfly
    Member
    Posted 1 year ago #

    After some more research it turns out that this problem is known to WordPress developers since quite a while with no solution yet available.

    A comment has been added to php source of /wp-includes/comment.php which points to http://core.trac.wordpress.org/ticket/9235

    A possible "easy" solution besides patching wp-config.php or similar seems to be a plugin like Proxy Real IP: http://wordpress.org/extend/plugins/proxy-real-ip/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic