Support » Plugin: WP ULike » Doesn’t Handle IP Address Lists

  • This plugin’s method for getting the IP address of the user does not work properly when the website is using certain types of caches and proxies. The result of this bug is that all likes are logged as coming from ‘127.0.0.1’.

    The issue seems to lie in the get_ip function in the wp-ulike.php file. Unfortunately, this code:

    if ( ! filter_var( $ip, FILTER_VALIDATE_IP ) ) {
    // Return local ip address
    return ‘127.0.0.1’;
    }

    fails when headers like x_forwarded_for are set to be a list of ip addresses, as is normally specified in their spec here:

    https://en.wikipedia.org/wiki/X-Forwarded-For#Format

    I am not a php expert, but I believe the proper code to handle this would be something like:

    $filter = false
    $ips = explode( ‘, ‘, $ip )
    foreach( $ips as $check ) {
    if ( ! filter_var( $check, FILTER_VALIDATE_IP ) ) {
    $filter = true
    }
    }

    if ( $filter ) {
    // Return local ip address
    return ‘127.0.0.1’;
    }

    I am more than happy to make a pull request on your github if you would like, I just want to see this resolved as I had to nuke the above code to make the plugin’s most recent version work.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Doesn’t Handle IP Address Lists’ is closed to new replies.