简体   繁体   中英

gii not working in yii

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

这是唯一对我有用的产品线:

'ipFilters'=>array($_SERVER['REMOTE_ADDR']),

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!!!)

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

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.

Why do I get a 403 error when trying to use Gii?

If the above link does not help any, try to lookout appplication.log file in runtime folder to see what is going wrong.

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'),
    ),

I had a very similar problem. For me it was that my user account didn't have writeaccess to my PHP session_save_path folder. When I browsed to it in Windows 7, it told me I needed permission and it would grant it if I chose OK. I did. Everything was fixed.

try this

    'gii' => array(
        'class' => 'system.gii.GiiModule',
        'password' => 'pasword',
        'ipFilters'=> false,
        'generatorPaths' => array(
            'bootstrap.gii'
        ),
    ),

Consider where your development server is located (same maching, LAN, WAN) and how your IP address changes towards the server.

  1. If your server is running on the same machine as does your client (the browser), you request the page from the localhost itself, thus your IP address is 127.0.0.1 and the default settings work.

  2. If your server is on a different machine but in your local area network (LAN), your IP address would typically look something like this 192.168.1.20 for the server. You can find it and adjust the code.

  3. If your server is across the web (WAN), then you would either have a

    • static IP address (if you are lucky)
    • or a dynamic IP address within a fixed range,
    • or worse, a more or less unpredictable dynamic IP address.

Only if the very last (unpredictable dynamic IP address) is the case, I would follow this answer by schmunk who also points out the risk.

Using $_SERVER['REMOTE_ADDR'] seems unnecessary to me.

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;
}
if (YII_ENV_DEV) {

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

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

After replace it by using this default code,

and user this url.

http://localhost/basic/web/index.php?r=gii

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM