How do I restore original visitor IP with MediaWiki?

 

NOTE: The second step only applies to MediaWiki versions 1.18.0 and older. Newer versions of MediaWiki have completely rewritten ProxyTools.php and the following code is no longer present.

  1. Open includes/GlobalFunctions.php
    At approximately line 370, change the following:
    $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
    to:
    $forward = "\t(proxied via {$_SERVER['HTTP_CF_CONNECTING_IP']}{$forward})";
  2. Open includes/ProxyTools.php
    Find at approximately line 79:
    if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
    and replace with:
    if ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
    Find at approximately line 80:
    $ipchain = array( IP::canonicalize( $_SERVER['REMOTE_ADDR'] ) );
    and replace with:
    $ipchain = array( IP::canonicalize( $_SERVER['HTTP_CF_CONNECTING_IP'] ) );
  3. Save and upload.

UPDATE: For versions around 1.27.1

  • Go to line 1232 in GlobalFunctions.php, change REMOTE_ADDR to HTTP_CF_CONNECTING_IP.
  • Next, go to WebRequest.php, in lines 1151 to line 1159, change REMOTE_ADDR to HTTP_CF_CONNECTING_IP. (approximately three lines to change).

 

Still not finding what you need?

The Cloudflare team is here to help. 95% of questions can be answered using the search tool, but if you can’t find what you need, submit a support request.

Powered by Zendesk