Extension of the CHttpRequest class supporting location information and reverse proxy support.

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.


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.


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 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;


This extension is on GitHub.

Be the first person to leave a comment

Please to leave your comment.

Create extension
No downloadable files yet