Noodlecode parody of spaghetti code

Cloudflare & phpBB3

Session handling in phpBB3 requires a user to use one IP address per session, therefore if your IP address changed, you will be prompt to login again.

Cloudflare is a web caching service that cache static contents of a website by acting as the nameserver that manage the website domain name. Therefore, every request to the domain name will pass through Cloudflare system first and any cached contents will be served from Cloudflare servers instead of the web hosting server.

However, when using Cloudflare service, the REMOTE_ADDR value for PHP $_SERVER will follow Cloudflare servers IP address. Therefore, you might face problem when using phpBB (or any other web app that rely on session tied to the IP address) with this service.

So, we need to edit phpBB session.php file to grab the correct variable for the users’ real IP address. Edit includes/session.php

Find:

$this->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? (string) $_SERVER['REMOTE_ADDR'] : '';

Replace with:

$this->ip = (!empty($_SERVER['HTTP_CF_CONNECTING_IP']))
          ? (string) $_SERVER['HTTP_CF_CONNECTING_IP']
          : ((!empty($_SERVER['REMOTE_ADDR'])) ? (string) $_SERVER['REMOTE_ADDR'] : '');

HTTP_CF_CONNECTING_IP is special header value passed by Cloudflare servers containing visitors’ real IP address, and in case this variable not set, we use the good ol REMOTE_ADDR

Categories: Notes

PHP Hooks System » « phpBB SEO Ultimate URL backslash in URL

5 Comments

  1. Cloudfare can optimize database access? my server get down because the huge acess to the mysql database.

    Im from Brazil, sorry my bad english

  2. Cloudflare would be useful if your site serve a lot of static pages (content that doesnt change often). I guess in your case if your site pages served by the cloudflare instead of direct accessing your server, it will reduce database access.
    If you want to optimize your database access, consider caching your content/sql result using apc, memcached or file based cache. Cache is useful for content that
    – doesn’t change often
    – involve heavy sql query
    – has high pagehits

  3. closing ceremonies 2012

    28 April 2014 — 9:34 am

    Awesome blog! Do you have any tips for aspiring writers? I’m planning to start my own website soon but I’m
    a little lost on everything. Would you propose starting with a free
    platform like WordPress or go for a paid option? There are so many options out
    there that I’m totally confused .. Any recommendations? Many thanks!

    Here is my site: closing ceremonies 2012

  4. Nigeria Forum Online

    29 July 2014 — 6:52 am

    Nice article.

    @closingceremonies2012, if you are a total newbie, start with a free blog. But if knowledged, start live!.

  5. Use the extension here for phpBB 3.1 and phpBB 3.2:
    http://www.sitesplat.com/phpBB3/viewtopic.php?t=3200
    It will fix the Cloudflare IP issues.

Leave a Reply

Your email address will not be published.

*

Copyright © 2017 Noodlecode