I'm tying to determine the correct order to assign an IP address to a variable so that proxies are handled correctly and the proper ip is identified. Based on the environment variables available.
The code thus far looks like this and I suppose I want to know if the elsif conditions are in the right order as I'm a bit hazy on how the whole thing works exactly. I suspect the $ENV{REMOTE_ADDR} check may need to be taken last.
Thoughts?
if($ENV{REMOTE_ADDR} && $ENV{REMOTE_ADDR} is valid){ $ourip = $ENV{REMOTE_ADDR} }
elsif($ENV{HTTP_X_FORWARDED_FOR} && $ENV{HTTP_X_FORWARDED_FOR} is valid){ $ourip = $ENV{HTTP_X_FORWARDED_FOR} }
elsif($ENV{HTTP_VIA} && $ENV{HTTP_VIA} is valid){ $ourip = $ENV{HTTP_VIA} }
elsif($ENV{HTTP_X_COMING_FROM} && $ENV{HTTP_X_COMING_FROM} is valid){ $ourip = $ENV{HTTP_X_COMING_FROM} }
elsif($ENV{HTTP_X_FORWARDED} && $ENV{HTTP_X_FORWARDED} is valid){ $ourip = $ENV{HTTP_X_FORWARDED} }
elsif($ENV{HTTP_FORWARDED} && $ENV{HTTP_FORWARDED} is valid){ $ourip = $ENV{HTTP_FORWARDED} }
elsif($ENV{HTTP_COMING_FROM} && $ENV{HTTP_COMING_FROM} is valid){ $sendip = $ENV{HTTP_COMING_FROM} }
elsif($ENV{HTTP_FORWARDED_FOR} && $ENV{HTTP_FORWARDED_FOR} is valid){ $sendip = $ENV{HTTP_FORWARDED_FOR} }