I'm building my site around geographical information from users to content so that everything can be easily related and found in the real-world.
I'm using mod_geoip2 to get location information for my site. I can pull location data from my visitors using Apache Notes:
$user_zip = apache_note("GEOIP_POSTAL_CODE"); print $user_zip;
$user_ip = apache_note("GEOIP_ADDR"); print $user_ip;
I'm attempting to integrate Smart IP with my own custom module so that if I distribute my module there won't have to be a requirement for mod_geoip2. The difficulty that I'm having is that when a visitor is behind a proxy server the IP address that is given is not the clients' but the proxy servers'. I have fixed this in mod_geoip by adding additional configuration. When a visitor pulls up their IP address using notes (code on a user page) they are given the correct IP address and location; however, when they pull their IP address using Smart IP:
$smarts_ip = $_SESSION['smart_ip']['location']['ip_address']; print $smarts_ip;
they are given the proxy address instead of the correct IP address. I'm not sure how this is happening since mod_geoip2 is selected as the source for Smart IP.
I've cleared my cache and tried a few times but always with the same result. Any help in this matter would be great.
Comments
Comment #1
birdsnbees commentedBefore I have issue getting the correct IP address of my visitors because its my Cloudflare IP address that my site getting instead of my visitors IP. Adding this code at settings.php solved my problem:
$_SERVER['REMOTE_ADDR'] = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];I hope this give you hint to your issue.
Comment #2
birdsnbees commentedComment #4
anurag27@spell
You are just amazing Man!!! You saved my couple of hours. I was trying to get rid of this solution since last 2 days and your comment saved me.
I have integrated Smart IP module (with CloudFlare CDN) in order to fetch User's current location and by default I was getting Los Angeles as default location. I debugged the code but didn't find exact solution and I found your comment which works perfectly fine for me.