Provides the enhanced components for the web request processing in Yii1 application

1.0.0 2024-07-12 14:45 UTC

This package is auto-updated.

Last update: 2024-09-12 15:09:11 UTC


README

The Enhanced Web Components Extension for Yii 1


This extension provides the enhanced components for the web request processing in Yii1 application.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yii1tech/web

or add

"yii1tech/web": "*"

to the "require" section of your composer.json.

Usage

This extension provides the enhanced components for the web request processing in Yii1 application.

In particular, it allows correct and secure processing of the "forwarded" HTTP headers, which is crucial for distributed application with load balancer.

Application configuration example:

<?php

return [
    'components' => [
        'request' => [
            'class' => yii1tech\web\HttpRequest::class,
            'trustedHosts' => [
                '192.168.0.0/24', // trust "forwarded" headers coming from IP addresses in range `192.168.0.0-192.168.0.254`
            ],
        ],
    ],
    // ...
];

Usage example:

<?php

var_dump(Yii::app()->request->getRemoteIP()); // returns IP of current HTTP connection, e.g. load balancer, outputs '192.168.0.1'
var_dump(Yii::app()->request->getUserIp()); // returns user IP address, considering "forwarded" headers, outputs '162.55.123.243'
var_dump(Yii::app()->request->getUserHostAddress()); // alias of `getUserIp()`