WordPress.org

Ready to get started?Download WordPress

Forums

Wordfence Security
Fatal error: Cannot redeclare geoip_country_code_by_name() (4 posts)

  1. T. Lee
    Member
    Posted 1 year ago #

    There is a function definition at line 432 of the wfGeoIP.php library that defines the function 'geoip_country_code_by_name'. This causes a fatal PHP error, because there is already a function by this name in the PHP GeoIP extension.

    I'm sure this library is to support country-based blocking. But I am unable to disable country-based blocking, because as soon as I re-enable Wordfence, it breaks my site and I can do nothing.

    Could someone please tell me how to disable country-based blocking through the database so that my blog won't have to be up, with its pants down? (I see no column for this in the wfConfig table.)

    Thanks,
    Terry

    http://wordpress.org/extend/plugins/wordfence/

  2. T. Lee
    Member
    Posted 1 year ago #

    Well I still have not learned how to disable country-based blocking by manually manipulating the database.

    However, I was able to get Wordfence working again by enclosing the two functions (that collide with the PHP GeoIP extension function names) inside "if (!function_exists())" blocks.

    Since I had to manually edit the Wordfence code, I do not consider this issue resolved.

  3. petee
    Member
    Posted 1 year ago #

    I had the same problem and did not find any support on Wordfence. Here is my solution that worked for me (but I am not sure if the problem will come back after a future Wordfence update)

    In: plugins/wordfence/lib/wfGeoIP.php on line 432

    Start on line 432 and replace this:

    function geoip_country_code_by_name($gi, $name) {
      $country_id = geoip_country_id_by_name($gi,$name);
      if ($country_id !== false) {
            return $gi->GEOIP_COUNTRY_CODES[$country_id];
      }
      return false;
    }
    function geoip_country_name_by_name($gi, $name) {
      $country_id = geoip_country_id_by_name($gi,$name);
      if ($country_id !== false) {
            return $gi->GEOIP_COUNTRY_NAMES[$country_id];
      }
      return false;
    }

    ************************With this:********************

    if (!function_exists('geoip_country_code_by_name')){
        function geoip_country_code_by_name($gi, $name) {
          $country_id = geoip_country_id_by_name($gi,$name);
          if ($country_id !== false) {
                return $gi->GEOIP_COUNTRY_CODES[$country_id];
          }
          return false;
        }
    }
    
    if (!function_exists('geoip_country_name_by_name_v6')){
        function geoip_country_name_by_name_v6($gi, $name) {
          $country_id = geoip_country_id_by_name_v6($gi,$name);
          if ($country_id !== false) {
                return $gi->GEOIP_COUNTRY_NAMES[$country_id];
          }
          return false;
        }
    }
    
    if (!function_exists('geoip_country_name_by_name')){
        function geoip_country_name_by_name($gi, $name) {
          $country_id = geoip_country_id_by_name($gi,$name);
          if ($country_id !== false) {
                return $gi->GEOIP_COUNTRY_NAMES[$country_id];
          }
          return false;
        }
    }

    It solved the problem for me.

  4. T. Lee
    Member
    Posted 1 year ago #

    Yes. That is exactly what I did: enclosed the offending functions within if-not-function_exists blocks. But I didn't bother with the 'v6' versions of the functions.

    Thanks for the code example. Hopefully it will help others until this is resolved at the source.

    Terry

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic