Skip to content

Instantly share code, notes, and snippets.

@kemo
Created June 14, 2011 11:46
Show Gist options
  • Save kemo/1024747 to your computer and use it in GitHub Desktop.
Save kemo/1024747 to your computer and use it in GitHub Desktop.
Security antispam check
<?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