| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
class IPHelper { |
| 10 |
/** |
| 11 |
* Retrieves the IP address of the current client. |
| 12 |
* |
| 13 |
* The method checks if the IP address is obtained from a shared internet, proxy, or remote address. |
| 14 |
* |
| 15 |
* @return string The IP address of the current client. |
| 16 |
*/ |
| 17 |
public static function getIPAdress(): string { |
| 18 |
//whether ip is from share internet |
| 19 |
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
| 20 |
$ip_address = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] ); |
| 21 |
} //whether ip is from proxy |
| 22 |
elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
| 23 |
$ip_address = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] ); |
| 24 |
} //whether ip is from remote address |
| 25 |
else { |
| 26 |
$ip_address = sanitize_text_field( $_SERVER['REMOTE_ADDR'] ); |
| 27 |
} |
| 28 |
|
| 29 |
return $ip_address; |
| 30 |
} |
| 31 |
} |