yii1tech / web
Provides the enhanced components for the web request processing in Yii1 application
Fund package maintenance!
klimov-paul
Patreon
Requires
- php: >=7.2
- yiisoft/yii: ~1.1.0
Requires (Dev)
- phpunit/phpunit: ^6.0 || ^7.0 || ^8.0 || ^9.3 || ^10.0.7
This package is auto-updated.
Last update: 2024-11-12 15:28:34 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.
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()`