IP Detection does not work
-
Hello,
I am trying to make use of the IP Detection feature since I am behind a Cloudfront instance and no matter the setting I always get the IPs of the load balancer and not of the actual user.
Running a simple PHP script off the Internet provides the correct information. This is the script I am running and always finds the correct information in the X-FORWARDED-FOR header as per the Cloudfront documentation.
<?php foreach ( array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) { if ( array_key_exists( $key, $_SERVER ) === true ) { foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) { $ip = trim( $ip ); // just to be safe if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) { return $ip; } } } }Can you look into the problem?
Thank you!
The topic ‘IP Detection does not work’ is closed to new replies.