Yii Framework Forum: Best way to implement an IP Filter - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Best way to implement an IP Filter Rate Topic: -----

#1 User is offline   sn0rcha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 22-June 09

Posted 05 March 2010 - 06:41 PM

Hey gurus!

I was wondering what you guys think is the best way to implement an IP filter, and also how I should go about executing a function on every page.

I have a model and controller that allows my end users admins to enter IP's that they want to block from having access to the site, they want to redirect these blocked IP's to an error page. I've written the controller function to check the IP of the visitor and redirect but am unsure how to have the function execute on every page without having to code it in all controllers.

Thanks
Sn0rcha
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 05 March 2010 - 07:55 PM

- You could use a parent-controller and make use of the beforeAction() method.
- You could make use of the onBeginRequest event.
- You could preload a special component.

Last solution could look like this:

class IPBlocker extends CApplicationComponent
{

   public function init()
   {

      // check if ip is blocked...

   }

}


Then in config:

...

preload => array('log', 'ipblocker'),

...

'components' => array(
   ...
   'ipblocker' => array(
      'class' => 'application.components.IPBlocker',
   ),
   ...
),

0

#3 User is offline   Theill11 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 03-March 10
  • Location:@ localhost

Posted 05 March 2010 - 08:25 PM

You could also use a filter. There is already CAccessControlFilter which has functionality for blocking IP-addresses.

If you want custom functionality you could create a class that extends from this or CFilter and then define it in the filters()-method of your parent controller.
0

#4 User is offline   sn0rcha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 22-June 09

Posted 05 March 2010 - 08:35 PM

View PostKomodo, on 05 March 2010 - 08:25 PM, said:

You could also use a filter. There is already CAccessControlFilter which has functionality for blocking IP-addresses.

If you want custom functionality you could create a class that extends from this or CFilter and then define it in the filters()-method of your parent controller.


Thanks for the replies guys, i'm still quite new at Yii but am loving it :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users