Jump to content

How to get real customer ip via CDN in prestashop?


Recommended Posts

Hi,

 

I use this module to get real order ip: http://www.presto-changeo.com/en/prestashop-free-modules/107-order-ip-address-verification.html

 

But there is a problem that I am using a cdn, so the real ip will be HTTP_X_FORWARDED_FOR but not REMOTE_ADDR

 

I got the following code, but I don't know how to insert into this module to make this function come true.

 

<?php
if ($_SERVER['HTTP_X_FORWARDED_FOR'] && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/',$_SERVER['HTTP_X_FORWARDED_FOR'])) {  
      $onlineip = $_SERVER['HTTP_X_FORWARDED_FOR'];  
} elseif  ($_SERVER['HTTP_CLIENT_IP']  && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/',$_SERVER['HTTP_CLIENT_IP'])) {  
      $onlineip = $_SERVER['HTTP_CLIENT_IP']; 
} elseif  ($_SERVER['REMOTE_ADDR']  && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/',$_SERVER['REMOTE_ADDR'])) {  
      $onlineip = $_SERVER['REMOTE_ADDR']; 
}
?>
 
This code makes that:
 
If visitor has HTTP_X_FORWARDED_FOR header, we will get HTTP_X_FORWARDED_FOR ip
else HTTP_CLIENT_IP
else REMOTE_ADDR
 
Can anyone help?
 
And I wanna this real can replace the one in registere customer log as well.
 
I just attach the module,so you don't need download from presto-changeo.com.

orderipaddressverification.zip

Link to comment
Share on other sites

×
×
  • Create New...