diff --git a/composer.json b/composer.json index c5376e1..f322372 100644 --- a/composer.json +++ b/composer.json @@ -1,31 +1,32 @@ { "name": "keruald/globalfunctions", "description": "Essential core global functions", "type": "library", "license": "BSD-2-Clause", "version": "0.5.1", "repositories": [ { "type": "vcs", "url": "https://github.com/keruald/globalfunctions" } ], "keywords": [ "keruald", "core", "global functions" ], "require": { - "php": ">=5.4.0" + "php": ">=7.1.0", + "keruald/omnitools": "^0.2.0" }, "require-dev": { "phpunit/phpunit": "^7" }, "autoload": { "files": ["core.php"] }, "support": { "irc": "irc://irc.freenode.net/wolfplex", "issues": "http://devcentral.nasqueron.org" } } diff --git a/core.php b/core.php index fa28f71..ccf00d9 100644 --- a/core.php +++ b/core.php @@ -1,208 +1,135 @@ block * * @param mixed $variable the variable to dump */ function dprint_r ($variable) { - echo '
'; - print_r($variable); - echo ''; + Debugger::printVariable($variable); } /** * Prints human-readable information about a variable, wrapped in a
block * then dies * * @param mixed $variable the variable to dump */ function dieprint_r ($variable) { - dprint_r($variable); - die; -}; + Debugger::printVariableAndDie($variable); +} /// /// Client information /// /** * Returns the full header or the IP part of it * * @param string $value the header value * @return string the IP part + * @deprecated */ function extract_client_ip_from_header ($value) { - if (strpos($value, ',') !== false) { - //Header contains 'clientIP, proxyIP, anotherProxyIP' - //The first value is so the one to return. - //See draft-ietf-appsawg-http-forwarded-10. - $ips = explode(',', $value, 2); - return trim($ips[0]); - } - - return $value; + return (new RemoteAddress($value))->getClientAddress(); } /** * Gets remote IP address. * * This is intended as a drop-in replacement for $_SERVER['REMOTE_ADDR'], * which takes in consideration proxy values, blindly trusted. * * @return string the remote address + * @deprecated Use Keruald\OmniTools\HTTP\Requests\Request::getRemoteAddress() */ function get_remote_addr () { - $candidates = [ - //Standard header provided by draft-ietf-appsawg-http-forwarded-10 - 'HTTP_X_FORWARDED_FOR', - - //Legacy headers - 'HTTP_CLIENT_IP', - 'HTTP_FORWARDED', - 'HTTP_FORWARDED_FOR', - 'HTTP_X_CLUSTER_CLIENT_IP', - 'HTTP_X_FORWARDED', - - //Default header if no proxy information could be detected - 'REMOTE_ADDR', - ]; - - foreach ($candidates as $candidate) { - if (array_key_exists($candidate, $_SERVER)) { - return extract_client_ip_from_header($_SERVER[$candidate]); - } - } - - return ''; + return Request::getRemoteAddress(); }