mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-02 00:32:15 +09:00
Add method to get real IP from CloudFlare headers
This commit is contained in:
parent
c23ebdb4aa
commit
343ad39b79
3 changed files with 47 additions and 23 deletions
|
|
@ -91,6 +91,29 @@ class IpFilter
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get real IP from CloudFlare headers.
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public static function getCloudFlareRealIP()
|
||||
{
|
||||
if (!isset($_SERVER['HTTP_CF_CONNECTING_IP']))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$cloudflare_ranges = (include RX_BASEDIR . 'common/defaults/cloudflare.php');
|
||||
foreach ($cloudflare_ranges as $cloudflare_range)
|
||||
{
|
||||
if (self::inRange($_SERVER['REMOTE_ADDR'], $cloudflare_range))
|
||||
{
|
||||
return $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given IPv4 address belongs to a IPv4 CIDR range with mask.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue