Original customer IP Address + Cloudflare

Hi,

I've got the store behind cloudflare firewall. Now, the thing is that I want to log the client IP address in the orders.

If I use

$_SERVER['REMOTE_ADDR']

I get back my cloudflare IP Address, but not the client ones. Could you kindly assist in this case?

Regards,
db

Thanks for the quick reply, Tim.

Well, I did.But the thing is that I've configured the store checkout so that guests  (not registered) can use it. And I've set some custom data in the fields for mysql database. The question is, how do I extract their IP addresses and store them in mysql? It's okay if I store them in any compatible column.

EDIT: After adding this:

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

the store won't load.

EDIT2:

I removed that, it works again.
My main requirement is that, in the email I receive when there is any purchase, I want to see the IP Address of the customer.

tim

What the code does is replace REMOTE_ADDR with the real IP so you can get it the usual way in PHP by $_SERVER['REMOTE_ADDR'].

There is missing a paranthesis at the end:

if (isset($_SERVER['HTTP_CF_VISITOR'])) {
This thread has been closed due to long inactivity. Posting to it is not possible.
View code on GitHub