Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

How to avoid gii console 403 error

$
0
0
A common stumbling block for using the yii framework is getting the 403 error "You are not allow to access this page" when setting up the gii module/console for access http : // {domain name}/{webapp name}/index.php?r=gii

To enable the gii module, comments have to be removed from the main.php file. Ensure the web user has access rights using chown or chmod, to edit and use this file.

/protected/conig/main.php

'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'PASSWORD',
'ipFilters'=>array('127.0.0.1','::1'),
),
),

adding $_SERVER['REMOTE_ADDR'] will get you past the 403 error, or you can add your address manually (better security)

'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'PASSWORD',
'ipFilters'=>array($_SERVER['REMOTE_ADDR'],'127.0.0.1','::1'),
),
),




This is because the server remote addr has to match the ipFilters address.

/yii/framework/web/CHttpRequest.php
public function getUserHostAddress()
{
return isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:'127.0.0.1';
}

The server remote addr defaults to your local address 127.0.0.1, if not set.

To bypass the check all together, you can change the code in the gii module, but this is not recommended on a production server.

/yii/framework/gii/GiiModule.php
protected function allowIp($ip)
{
if(empty($this->ipFilters))
return true;
foreach($this->ipFilters as $filter)
{
if($filter==='*' || $filter===$ip || (($pos=strpos($filter,'*'))!==false && !strncmp($ip,$filter,$pos)))
return true;
}
//return true; /** CHANGE RETURN FALSE TO TRUE AND YOU WILL GET IN TO GII **/
return false;
}

Quick Tip By Marvelous Light Services http ://www.marvelouslightservices.com

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>