Request::ips PHP Method

ips() public static method

Returns the client IP addresses.
public static ips ( ) : array
return array
        public static function ips()
        {
            return \Illuminate\Http\Request::ips();
        }

Usage Example

Example #1
0
function handleHttpError($httpStatusCode, $options = [])
{
    switch ($httpStatusCode) {
        case 400:
            $httpStatusName = 'Bad request';
            $httpDescription = 'The server cannot or will not process the request due to a client error.';
            $level = 'notice';
            break;
        case 401:
            $httpStatusName = 'Unauthorized';
            $httpDescription = 'The request has not been applied because it lacks valid authentication credentials for the target resource.';
            $level = 'notice';
            break;
        case 403:
            $httpStatusName = 'Forbidden';
            $httpDescription = 'The server understood the request but refuses to authorize it.';
            $level = 'notice';
            break;
        case 404:
            $httpStatusName = 'Not found';
            $httpDescription = 'The server did not find a current representation for the target resource.';
            $level = 'notice';
            break;
        case 405:
            $httpStatusName = 'Method not allowed';
            $httpDescription = 'The method received in the request is known by the server but not supported by the target resource.';
            $level = 'notice';
            break;
        case 422:
            $httpStatusName = 'Unprocessable entity';
            $httpDescription = 'The request was well-formed but was unable to be followed due to semantic errors.';
            $level = 'notice';
            break;
        case 500:
            $httpStatusName = 'Internal Server Error';
            $httpDescription = 'The server encountered an unexpected condition which prevented it from fulfilling the request.';
            $level = 'error';
            break;
        default:
            $httpStatusName = $httpStatusCode;
            $httpDescription = $httpStatusCode;
            $level = 'error';
    }
    $description = isset($options['description']) ? $options['description'] : $httpDescription;
    if (!isset($options['log']) or $options['log'] == true) {
        Log::$level($httpStatusCode . ' ' . $httpStatusName . ': ' . Request::fullUrl(), ['description' => $description, 'url' => Request::fullUrl(), 'headers' => Request::header(), 'ips' => Request::ips()]);
    }
    if (!isset($options['source']) or $options['source'] == 'gui') {
        return Response::view('errors.default', ['title' => $httpStatusCode . ' ' . $httpStatusName, 'description' => $description], $httpStatusCode);
    } elseif (isset($options['source']) && $options['source'] == 'api') {
        $response = Response::make(['message' => $description], $httpStatusCode);
        if ($httpStatusCode == 401) {
            $response->header('WWW-Authenticate', 'Lanager');
        }
        return $response;
    }
}