Created
June 24, 2020 16:40
-
-
Save Elshaden/9f1b689ed6d3cf0f105b4c9020417a03 to your computer and use it in GitHub Desktop.
IP white List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Containers\Authentication\Actions; | |
use Symfony\Component\HttpFoundation\IpUtils; | |
class IpWhiteList | |
{ | |
/** | |
* A Class to Validate request IP against array of IP's | |
* @return bool | |
*/ | |
public function checkIP(){ | |
// White List Ip's | |
$ips = ['x.x.x.x','x.x.x.x']; | |
return IpUtils::checkIp($this->getIp(), $ips); | |
} | |
/** | |
* @return mixed|null | |
*/ | |
private function getIp(){ | |
$ipaddress = ''; | |
if (isset($_SERVER['HTTP_CLIENT_IP'])) | |
$ipaddress = $_SERVER['HTTP_CLIENT_IP']; | |
else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) | |
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
else if (isset($_SERVER['HTTP_X_FORWARDED'])) | |
$ipaddress = $_SERVER['HTTP_X_FORWARDED']; | |
else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) | |
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; | |
else if (isset($_SERVER['HTTP_FORWARDED'])) | |
$ipaddress = $_SERVER['HTTP_FORWARDED']; | |
else if (isset($_SERVER['REMOTE_ADDR'])) | |
$ipaddress = $_SERVER['REMOTE_ADDR']; | |
else | |
$ipaddress = null; | |
return $ipaddress; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment