function cleantalk_get_real_ip in Anti Spam by CleanTalk 8
Same name and namespace in other branches
- 7 cleantalk.module \cleantalk_get_real_ip()
- 7.2 cleantalk.module \cleantalk_get_real_ip()
1 call to cleantalk_get_real_ip()
- Cleantalk::ct_session_ip in src/
Cleantalk.php - Get user IP behind proxy server
File
- ./
cleantalk.module, line 126 - Main CleanTalk integration module functions.
Code
function cleantalk_get_real_ip() {
if (function_exists('apache_request_headers')) {
$headers = apache_request_headers();
}
else {
$headers = $_SERVER;
}
if (array_key_exists('X-Forwarded-For', $headers) && filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$the_ip = $headers['X-Forwarded-For'];
}
elseif (array_key_exists('HTTP_X_FORWARDED_FOR', $headers) && filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$the_ip = $headers['HTTP_X_FORWARDED_FOR'];
}
else {
$the_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
}
return $the_ip;
}