@Findus23 opened this Issue on June 25th 2017 Member

From https://forum.piwik.org/t/geoip-conflict-w-wordfence/24651

If piwik is using the same geoip database as the wordpress plugin "wordfence" (via the GeoIP (Php) location provider) the following error occurs:

Fatal error: Cannot redeclare geoip_load_shared_mem() (previously declared in 
/home/USERNAME/public_html/wp-content/plugins/wordfence/waf/wfWAFGeoIP.php:240) in 
/home/USERNAME/public_html/analytics/libs/MaxMindGeoIP/geoip.inc on line 1444

I am not sure why two seperate php scripts are able to interfere, but it seems like this has happened to other projects.

A simple fix seems to be similar to this one: https://github.com/solarissmoke/Simple-Stats/commit/e25c459bb3600939c8fdd018e7094452c52f6334

@mattab commented on June 25th 2017 Owner

Thanks for the report @Findus23 - the issue is that our geoip file cannot be included twice, which Wordfence has bundled the copy as well causing the error in our code. To solve this i think we need to wrap the file in a !class_exists looking whether GeoIp is already defined and possibly also wrap the functions below in function_exists.

@RobsImpSS commented on July 7th 2017

Hopefully a fix will be included in the next update but is there a temporary fix for this issue as I have not had any statistics for well over a month now?

Thanks...

@mattab commented on July 8th 2017 Owner

@RobsImpSS if you are using WP-Piwik with the "PHP" connection mode, try replace it with the "HTTP" option instead? this should fix the issue

@RobsImpSS commented on July 9th 2017

I'm not using the WP-Piwik, just the regular version with the code inserted into the footer of WP. The reason why I do this is because I have a folder of website templates that I track and these are not created through WP.

As stated above, I get the fatal error in the Administration when I click the link to do a system check or click the Geolocation link. Piwik has always worked fine but I guess recent updates by Wordfence is conflicting with Piwik.

@mattab commented on July 10th 2017 Owner

I don't quite understand how it is possible that wordfence influences Piwik in that way. When you load Piwik Administration screen, Wordfence/other tools shouldn't be able to affect the Piwik page rendering. Do you have some insights on why this is the case?

@RobsImpSS commented on July 11th 2017

I am just a regular user of Piwik and it has always worked fine until about approx. 1.5 months ago. Then all of a sudden Piwik stopped recording visits and when I clicked on the System Check link in the Administration area, I got the error. I got the same error when I clicked on the Geolocation link as well.

Fatal error: Cannot redeclare geoip_load_shared_mem() (previously declared in
/home/USERNAME/public_html/wp-content/plugins/wordfence/waf/wfWAFGeoIP.php:240) in
/home/USERNAME/public_html/analytics/libs/MaxMindGeoIP/geoip.inc on line 1444

I then deleted my database and installed a fresh copy of Piwik, but the results were the same. I then disabled Wordfence and Piwik started recording visits again. So it was obvious that there was a conflict with Wordfence and that is when I opened a help request on the Piwik forum.

@Findus23 commented on July 11th 2017 Member

Maybe I know the cause and a possible solution:

Yesterday someone in the forum had a pretty similar issue: https://forum.piwik.org/t/piwik-konflikt-mit-wordfence-via-wordpress/24888/

His host recommended him to add php_value auto_prepend_file none into piwiks .htaccess, which solves the issue for him.

It seems like wordfence uses this php setting (with the help of an .user.ini php config or (if unsupported) with a .htaccess config entry) to insert a php file at the beginning of every file that gets executed (so also the piwik files), which causes this error.

@RobsImpSS commented on July 12th 2017

I added it to the .htaccess file located in the config folder. Is that the right location? I copied and pasted it just as you typed it and it didn't fix it. Was copying and pasting okay or was I supposed to add any other characters?

@Findus23 commented on July 12th 2017 Member

I think the problem it that the line needs to be added to the .htaccess in the piwik root directory, as all piwik files shouldn't be prepended with wordfence code.

@RobsImpSS commented on July 12th 2017

The Piwik root directory does not have a .htaccess file. I added a new .htaccess file to the Piwik root with the code you supplied and it caused a 404 error.

@RobsImpSS commented on July 14th 2017

mattab,

Have you come up with anything yet?

@Findus23 commented on July 14th 2017 Member

The Piwik root directory does not have a .htaccess file. I added a new .htaccess file to the Piwik root with the code you supplied and it caused a 404 error.

Hi,
changing an php setting inside an .htaccess shouldn't cause an 404. Can you check the php error log or the apache error log to see why this happens?

@RobsImpSS commented on July 14th 2017

Here is the error I got (website url redacted):

[Fri Jul 14 11:12:58.251686 2017] [core:alert] [pid 246202:tid 140061798520576] [client 00.00.00.00:64124] /home/username/public_html/analytics/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration, referer: http://www.website.com/analytics/?module=CoreAdminHome&action=home&idSite=1&period=range&date=last30

Powered by GitHub Issue Mirror