MediaWiki behind CloudFlare

When you set up with CloudFlare with MediaWiki, the IP won’t be showing correctly. Here is the how-to derived from CloudFlare’s official MediaWiki FAQ. The official document is old and doesn’t work for the latest version of MediaWiki.


The modifications below are based on version MediaWiki 1.22.4
First edit includes/GlobalFunctions.php:

Around line 1201 from

$forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";

Change to

$forward = "\t(proxied via {$_SERVER['HTTP_CF_CONNECTING_IP']}{$forward})";

Edit WebRequest.php, find line near

$ipchain = $_SERVER['REMOTE_ADDR'];

Around line 1097 to 1108, change all REMOTE_ADDR to HTTP_CF_CONNECTING_IP.

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.