diff --git a/src/Payfast.php b/src/Payfast.php index d6bb4d4..df36e3c 100644 --- a/src/Payfast.php +++ b/src/Payfast.php @@ -193,9 +193,10 @@ public function validSignature($signature) public function validateHost($request) { - $hosts = $this->getHosts(); + $hosts = $this->getHosts(); + $HTTPXForwardedFor = $this->getHTTPXForwardedFor($request); - if( !in_array( $request->server('REMOTE_ADDR'), $hosts ) ) + if( !in_array( $request->server('REMOTE_ADDR'), $hosts ) && !in_array( $HTTPXForwardedFor, $hosts ) ) { throw new Exception('Not a valid Host'); } @@ -218,6 +219,16 @@ public function getHosts() return array_unique($hosts); } + public function getHTTPXForwardedFor($request) + { + $host = ''; + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $hosts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); + $host = trim(end($hosts)); + } + return $host; + } + public function validateAmount($grossAmount) { if($this->amount === $this->newMoney($grossAmount)->convertedAmount()) {