Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_ip_address()
- {
- if (!empty($_SERVER['HTTP_CLIENT_IP']) && validate_ip($_SERVER['HTTP_CLIENT_IP'])) {
- return $_SERVER['HTTP_CLIENT_IP'];
- }
- if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
- $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
- foreach ($iplist as $ip) {
- if (validate_ip($ip))
- return $ip;
- }
- } else {
- if (validate_ip($_SERVER['HTTP_X_FORWARDED_FOR']))
- return $_SERVER['HTTP_X_FORWARDED_FOR'];
- }
- }
- if (!empty($_SERVER['HTTP_X_FORWARDED']) && validate_ip($_SERVER['HTTP_X_FORWARDED']))
- return $_SERVER['HTTP_X_FORWARDED'];
- if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
- return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
- if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && validate_ip($_SERVER['HTTP_FORWARDED_FOR']))
- return $_SERVER['HTTP_FORWARDED_FOR'];
- if (!empty($_SERVER['HTTP_FORWARDED']) && validate_ip($_SERVER['HTTP_FORWARDED']))
- return $_SERVER['HTTP_FORWARDED'];
- return $_SERVER['REMOTE_ADDR'];
- }
- function ip_in_range($ip, $range) {
- if (strpos($range, '/') == false)
- $range .= '/32';
- list($range, $netmask) = explode('/', $range, 2);
- $range_decimal = ip2long($range);
- $ip_decimal = ip2long($ip);
- $wildcard_decimal = pow(2, (32 - $netmask)) - 1;
- $netmask_decimal = ~ $wildcard_decimal;
- return (($ip_decimal & $netmask_decimal) == ($range_decimal & $netmask_decimal));
- }
- function _cloudflare_CheckIP($ip) {
- $cf_ips = array(
- '199.27.128.0/21',
- '173.245.48.0/20',
- '103.21.244.0/22',
- '103.22.200.0/22',
- '103.31.4.0/22',
- '141.101.64.0/18',
- '108.162.192.0/18',
- '190.93.240.0/20',
- '188.114.96.0/20',
- '197.234.240.0/22',
- '198.41.128.0/17',
- '162.158.0.0/15',
- '104.16.0.0/12',
- );
- $is_cf_ip = false;
- foreach ($cf_ips as $cf_ip) {
- if (ip_in_range($ip, $cf_ip)) {
- $is_cf_ip = true;
- break;
- }
- } return $is_cf_ip;
- }
- function _cloudflare_Requests_Check() {
- $flag = true;
- if(!isset($_SERVER['HTTP_CF_CONNECTING_IP'])) $flag = false;
- if(!isset($_SERVER['HTTP_CF_IPCOUNTRY'])) $flag = false;
- if(!isset($_SERVER['HTTP_CF_RAY'])) $flag = false;
- if(!isset($_SERVER['HTTP_CF_VISITOR'])) $flag = false;
- return $flag;
- }
- function isCloudflare() {
- $ipCheck = _cloudflare_CheckIP($_SERVER['REMOTE_ADDR']);
- $requestCheck = _cloudflare_Requests_Check();
- return ($ipCheck && $requestCheck);
- }
- function getRequestIP() {
- $check = isCloudflare();
- if($check) {
- return $_SERVER['HTTP_CF_CONNECTING_IP'];
- } else {
- return $_SERVER['REMOTE_ADDR'];
- }
- }
- ------
- $ixp = getRequestIP();
- call $ixp in webhook
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement