RocketLoader and CF Real IP Function

rocketloader

#1

Hi there,

Been a long time cloudflare user but first time in here. So, I have a question that I hope someone could help me with.

I have a script on my website that need to get the visitor real ip address. And based on cloudflare KB page, I can achieve this by using the guide on this page : https://support.cloudflare.com/hc/en-us/articles/200170706-How-do-I-restore-original-visitor-IP-with-Nginx-

At first, the real IP address won’t be shown on my webpage. I’ve been tinkering around about a day and it always failed. And then decided to test it using my other domain on cloudflare, and somehow the script that I placed on this domain is always works. So, I check all the setting on both domain, and the difference that on the first domain I enabled Rocket Loader and on the second one I didn’t.

It seems Rocket Loader in conflicting on the real ip function, so it won’t show the real IP even after all the extra config being placed. Disabling the Rocket Loader function, and clearing the cache instantly enable the first site getting the real visitor IP.

Is this a bug or is it on purposely designed like that? Also how if I want to get the real IP and still want to enable the Rocket Loader function?

Thanks


#2

Hi,

Have you tried this step?


#3

I’ve used this snippet of PHP in the past to set the visitors IP in a variable for further use (regardless of it being direct or Cloudflare proxied traffic):

$client_ip = (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) ? ($_SERVER["HTTP_CF_CONNECTING_IP"]) : $_SERVER['REMOTE_ADDR'];

It’s been a while since I used it so not sure if this suffers from the issue you have of failing when RocketLoader is used but I’m pretty sure I didn’t have any errors when I was using it. This was a while back though but may be worth a try??

EDIT: Just realised that naturally this wouldn’t have been impacted by RocketLoader as it’s all server-side and I guess you’re using client-side JS?? However I’ll leave it here just in case anyone with similar issues see your thread in future. your best bet is prob disabling RL for your script as @GulshanKumar suggests.