User Tools

Site Tools


How To Configure LiteCart With CloudFlare

CloudFlare offers some great opportunities for merchants. And a whole bunch of features are available free.

How to setup LiteCart with CloudFlare Flexible SSL

This guide will assume you have no current SSL certificate for your website and running on a non-encypted HTTP connection.

1. Start by getting to know CloudFlare, see the presentation video at When you get a good understanding of their services sign up for an account.

2. Add your first website to CloudFlare and follow the wizard. Make sure your domain is enabled for tunneling via CloudFlare. When the guide is completed you are asked to change your domain servers.

3. In your CloudFlare domain profile, go to the app named Crypto and set SSL to Flexi.

Flexible SSL: An encrypted connection is established between your visitors and CloudFlare, but not from CloudFlare to your server.

4. In your LiteCart installation. Open ~/includes/ and insert the following lines at the bottom:

if (isset($_SERVER['HTTP_CF_VISITOR']) {
  if (preg_match('#https#i', $_SERVER['HTTP_CF_VISITOR'])) {
    $_SERVER['HTTPS'] = 'On';
    $_SERVER['SERVER_PORT'] = 443;

5. To preset the visitor's country, sent by CloudFlare determined by IP geo location. Edit ~/includes/library/

On line ~130, find

    // Get country from browser locale

Before that, add

    // Get country from HTTP header (CloudFlare)
      if (empty(self::$data['country_code'])) {
        if (!empty($_SERVER['HTTP_CF_IPCOUNTRY']) && in_array($_SERVER['HTTP_CF_IPCOUNTRY'], $countries)) {
          self::$data['country_code'] = $_SERVER['HTTP_CF_IPCOUNTRY'];

Now wait until your CloudFlare Flexi SSL states it is ready. If it is you should be able to access your site over a HTTPS connection

5. To force all users over a secure HTTPS link. Edit the file ~/.htaccess and add the following .htaccess mod_redirect directives:

# Force HTTPS (CloudFlare Flexible SSL)
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

That's all folks.

Note: Over a HTTPS connection you need to make sure you are not serving any images, javascripts or external components over non-encrypted HTTP. Your browser's debug tool is your friend (Press F12).

how_to_configure_litecart_with_cloudflare.txt · Last modified: 2020/08/16 17:19 by A User Not Logged in