Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot redeclare geoip_load_shared_mem() when running together with wordfence #11817

Closed
Findus23 opened this issue Jun 25, 2017 · 14 comments
Closed
Labels
answered For when a question was asked and we referred to forum or answered it.

Comments

@Findus23
Copy link
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: solarissmoke/Simple-Stats@e25c459

@mattab
Copy link
Member

mattab commented Jun 25, 2017

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
Copy link

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
Copy link
Member

mattab commented Jul 8, 2017

@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
Copy link

RobsImpSS commented Jul 9, 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
Copy link
Member

mattab commented Jul 10, 2017

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
Copy link

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
Copy link
Member Author

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
Copy link

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
Copy link
Member Author

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
Copy link

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
Copy link

mattab,

Have you come up with anything yet?

@Findus23
Copy link
Member Author

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
Copy link

RobsImpSS commented Jul 14, 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

@sgiehl
Copy link
Member

sgiehl commented May 10, 2021

This shouldn't be an issue anymore as we meanwhile switched to GeoIP2.

@sgiehl sgiehl closed this as completed May 10, 2021
@mattab mattab added the answered For when a question was asked and we referred to forum or answered it. label May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Projects
None yet
Development

No branches or pull requests

4 participants