We are using Amazon Web Services (AWS) for hosting and load balancing (among others). When using load balancing or other types of reversed proxies, the request tends to originate from the load balancer or proxy instead of from the user itself. Therefore, some functions in CHttpRequest return information about the proxy or load balancer instead of the user.This class extends CHttpRequest for that purpose and provides user location information.
Requirements ¶
This extension makes use of the EHttpClient (make sure you autoload the client or import the class before using this extension) and should run on Yii v1.1.5 till v1.1.9.
Usage ¶
Once unpacked in extensions, the extension can be implemented and use like in this example.
Your configuration file:
...
'request' => array(
'class' => 'application.extensions.EHttpRequest',
'useReverseProxyHeaders'=>true,
),
...
useReverseProxyHeaders tells whether to search for headers added by reverse proxies (e.g. load balancers).
Use of the extension:
$city = Yii::app()->request->userCity;
$countryCode = Yii::app()->request->userCountryCode;
$countryName = Yii::app()->request->userCountryName;
$hostAddress = Yii::app()->request->userHostAddress;
$isSecureConnection = Yii::app()->request->isSecureConnection;
Resources ¶
This extension is on GitHub.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.