可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
回答1:
This is the only line that worked for me:
'ipFilters'=>array($_SERVER['REMOTE_ADDR']),
回答2:
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!!!)
回答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..
回答4:
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.
回答5:
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.
回答6:
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'),
),
回答7:
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.
回答8:
try this
'gii' => array(
'class' => 'system.gii.GiiModule',
'password' => 'pasword',
'ipFilters'=> false,
'generatorPaths' => array(
'bootstrap.gii'
),
),
回答9:
Consider where your development server is located (same maching, LAN, WAN) and how your IP address changes towards the server.
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.
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.
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.
回答10:
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;
}
回答11:
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