gii not working in yii

2019-02-12 22:04发布

I am new in yii framework. In my site gii shows the error

Error 403 You are not allowed to access this page.

I set the gii in the config file like this

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

still it show the error

标签: php yii gii
11条回答
混吃等死
2楼-- · 2019-02-12 22:31

Following on from sandy8086's good answer. If your remote host is dual stacked (IPv6/IPv4) then you may have a dynamic IPv6 address automatically allocated in your subnet prefix range. The IPv4 method of using a wildcard '*' can also be adopted with the IPv6 address, thus: 'ab01:1234:5678:abcd:*', if you had a /64 prefix, this would match any address on your IPv6 network. This worked for me and got when I had trouble with the 'Error 403' and the penny dropped when I discovered, using Yii::app()->request->userHostAddress, that I was connecting via IPv6.

查看更多
叼着烟拽天下
3楼-- · 2019-02-12 22:33

To fix this, look in your main config file for the modules section for Gii, and add an

ipFilters array that includes your own IP:

// protected/config/main.php

return array(

...

'modules' => array(

    'gii' => array(

        'class'     => 'system.gii.GiiModule',

        'password'  => 'Enter Your Password Here',

        'ipFilters' => array('127.0.0.1', '192.168.1.7'),   // EDIT TO TASTE

    ),

    ...

The ipFilters property can include as many items as you like, and they can be straight

IP addresses or wildcards such as "192.168.1.*".

IPv6 addresses are supported as well if the underlying platform supports it, and "::1"

represents localhost (which may be required in some configurations).

Be careful not to open Gii to a too-wide audience lest it become a security risk.

Note: Yii 1.1.6 adds the default filter directly to the stock config file:

// If removed, Gii defaults to localhost only. Edit carefully to taste.

'ipFilters'=>array('127.0.0.1','::1'),

hope solved your problem..

查看更多
贪生不怕死
4楼-- · 2019-02-12 22:34

I was getting the same error. I checked my IP with Yii::app()->request->userHostAddress; turns out that this is returning an IPv6 address which looks something liks this ab01::1. This may be the behavior especially if you are using Safari (on OS X ... Chrome on OS X is showing the normal 127.0.0.1 IP. Strangely odd behavior from these two WebKit browsers).

So, simply put Yii::app()->request->userHostAddress in one of your views, and then copy the result from the output, and paste it in config/main.php:

    'gii'=>array(
        ...
        // If removed, Gii defaults to localhost only. Edit carefully to taste.
        'ipFilters'=>array('127.0.0.1','192.168.1.*','ab01::1','::1'),
    ),
查看更多
迷人小祖宗
5楼-- · 2019-02-12 22:39

You may set...

'ipFilters' => false

From the docs http://www.yiiframework.com/doc/api/1.1/GiiModule#ipFilters-detail ...

If you want to allow all IPs to access gii, you may set this property to be false (DO NOT DO THIS UNLESS YOU KNOW THE CONSEQUENCE!!!)

查看更多
时光不老,我们不散
6楼-- · 2019-02-12 22:39

Make sure theres no pregenerated config at the bottom of the config file. Those will overwrite whatever you added above:

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\debug\Module';

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = 'yii\gii\Module';
}

Should become (example, allows anyone):

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $secure = ['allowedIPs' => ['*']];

    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = ['class' => 'yii\debug\Module'] + $secure;

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = ['class' => 'yii\gii\Module'] + $secure;
}
查看更多
冷血范
7楼-- · 2019-02-12 22:43

This is the only line that worked for me:

'ipFilters'=>array($_SERVER['REMOTE_ADDR']),
查看更多
登录 后发表回答