Skip to content

Commit

Permalink
Fixed the checkip.dydns.com function to have a fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Smit committed Oct 6, 2021
1 parent d081f18 commit b287a85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions Helpers/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Wrapper\Helpers;

use Throwable;

class App
{
public function toXML($array, $rootElement = null, $xml = null) {
Expand Down Expand Up @@ -34,9 +36,13 @@ public function toXML($array, $rootElement = null, $xml = null) {

public function getIpAddress(): string
{
$externalContent = file_get_contents('http://checkip.dyndns.com/');
preg_match('/Current IP Address: \[?([:.0-9a-fA-F]+)\]?/', $externalContent, $m);
return $m[1];
try {
$externalContent = @file_get_contents('http://checkip.dyndns.com/');
preg_match('/Current IP Address: \[?([:.0-9a-fA-F]+)\]?/', $externalContent ?? "", $m);
return $m[1] ?? $_SERVER['REMOTE_ADDR'];
} catch (Throwable $ex) {
return $_SERVER['REMOTE_ADDR'];
}
}

public function initializeSoapClient($WSDL, $KeyCert = "", $Location = "") {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A wrapper to ease integration into Wirecard (previously MyGate) webservices.",
"license": "MIT",
"minimum-stability": "stable",
"version": "1.1.1",
"version": "1.1.2",
"authors": [
{
"name": "Christopher Smit",
Expand Down

0 comments on commit b287a85

Please sign in to comment.