Another Gii Question

Is there a way to set Gii to work only when logged on to localhost?

At it’s simplest you could have 2 config files (main.php)… one for dev, one for live :)

Perhaps you could also do it programatically by checking for the existence of “localhost” in “$_SERVER[‘SERVER_NAME’]” (stripos() maybe?) before adding gii to your configuration?

For example…




if(stripos('http://localhost/', $_SERVER['SERVER_NAME']) === 1) {

    ...gii config stuff

}



UNTESTED :)

This is what I have




   'modules'=>array(

       'gii'=>array(

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

           'password'=>'admin',

           'ipFilters'=>array('127.0.0.1', '192.168.4.18'),

       ),

   ),



Maybe try this:




if(stripos('http://localhost/', $_SERVER['SERVER_NAME']) === 1) {

    'modules'=>array(

       'gii'=>array(

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

           'password'=>'admin',

           'ipFilters'=>array('127.0.0.1', '192.168.4.18'),

       ),

   ),

}



Or even:




if((stripos('http://127.0.0.1/', $_SERVER['SERVER_NAME']) === 1) || (stripos('http://192.168.4.18/', $_SERVER['SERVER_NAME']) === 1))) {

    'modules'=>array(

       'gii'=>array(

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

           'password'=>'admin',

           'ipFilters'=>array('127.0.0.1', '192.168.4.18'),

       ),

   ),

}



depending on how you access localhost on your puter.

Haven’t tried this method myself but it could work :)

http://www.yiiframework.com/doc/cookbook/32/

Hmm, perhaps it’s also as simple as adding ‘localhost’ to the ipFilters array?

Give it a try and let me know lol :)

#- Not checked the docs, just stabbing in the dark.

As it says in the documentation

So for localhost you don’t need to configure anything… If you try to access gii from some other IP you get Error 403 (you are not allowed to access this page)