Skip to content
/ web Public

Provides enhanced components for the web request processing

License

Notifications You must be signed in to change notification settings

yii1tech/web

Repository files navigation

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()`

About

Provides enhanced components for the web request processing

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages