gii not working in yii
Asked Answered
T

11

9

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

Tropophilous answered 3/8, 2012 at 9:37 Comment(3)
can you check the output of Yii::app()->request->userHostAddress?Grudging
Are you already logged in when you trying to access gii? Did you made any changes at the UserIdentity.php?Maidenhair
Try removing your yii app cookies!! yiiframework.com/forum/index.php/topic/…Ranjiv
V
10

This is the only line that worked for me:

'ipFilters'=>array($_SERVER['REMOTE_ADDR']),
Vulcan answered 30/12, 2012 at 16:26 Comment(3)
Do you realize that this is a security risk? IP filters are there for a reason. What if that file makes it to a production system?Bendigo
This is a security risk, however, if you are aware of what you are doing and have a strong access password this can be very useful. Thanks for the solution.Pussyfoot
Simply disable the ip filters authentication if you're going to use this. Horrible idea though.Smelser
O
4

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

Overtake answered 5/2, 2013 at 22:37 Comment(0)
P
3

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

Poseidon answered 3/8, 2012 at 9:43 Comment(1)
I already read article. According to this I added my ip But it show the errorTropophilous
C
1

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.

Copenhagen answered 5/2, 2013 at 22:3 Comment(0)
R
0

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.

Rattly answered 8/8, 2012 at 5:24 Comment(0)
C
0

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'),
    ),
Carliecarlile answered 26/12, 2012 at 7:1 Comment(0)
M
0

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.

Mic answered 12/5, 2013 at 1:19 Comment(0)
G
0

try this

    'gii' => array(
        'class' => 'system.gii.GiiModule',
        'password' => 'pasword',
        'ipFilters'=> false,
        'generatorPaths' => array(
            'bootstrap.gii'
        ),
    ),
Grantee answered 22/7, 2013 at 10:13 Comment(0)
L
0

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.

Lauranlaurance answered 3/3, 2014 at 18:41 Comment(0)
I
0

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;
}
Intranuclear answered 27/7, 2014 at 13:21 Comment(0)
S
0
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

Supplementary answered 14/1, 2017 at 7:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.