Created
June 14, 2011 11:46
-
-
Save kemo/1024747 to your computer and use it in GitHub Desktop.
Security antispam check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
/** | |
* @author kemo <github.com/kemo> | |
*/ | |
class Security extends Kohana_Security { | |
/** | |
* Logs the timed purpose to session | |
* @param string purpose | |
* @return void | |
*/ | |
public static function log($purpose) | |
{ | |
$submits = (array) Session::instance()->get('Security::spam', array()); | |
$submits[$purpose] = time(); | |
Session::instance()->set('Security::spam', $submits); | |
} | |
/** | |
* Checks if purpose is being spammed | |
* Usage: $validation->rule('whatever', 'Security::antispam', array('contact us', 30)); | |
* | |
* @param string purpose | |
* @return bool | |
*/ | |
public static function antispam($purpose, $seconds = 30) | |
{ | |
$submits = (array) Session::instance()->get('Security::spam', array()); | |
$last = Arr::get($submits, $purpose, 0); | |
return ! (time() - $last < $seconds); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment