Hej,
luźny temat z pytaniem co myślicie to tej małej klasie:
Jej zadaniem ma być sprawdzenie jeszcze w bootstrapie czy akcje zadań są wykonywane przez usera a nie bota itd.
/**
* @author Spawnm
* @license New BSD License
*/
class security_request
{
/**
* @param array $data
*/
public function initGET
(array $data) {
if($_GET){
foreach($data as $key){
if( isset($_GET[ $key ] ) && !isset($_SERVER['HTTP_REFERER'] )){ throw new Exception('initGET: security failed.');
}
if( isset($_GET[$key]) && !$this->refererIsLocal() ){ throw new Exception('initGET: security failed.');
}
}
}
}
/**
* @return bool
*/
public function refererIsLocal()
{
$host = $host['host'];
$local = $_SERVER['HTTP_HOST'];
return ($host === $local )? true : false;
}
/**
* @param array $data
*/
public function initPOST
(array $data) {
if($_POST){
foreach($data as $key){
if( isset($_POST[ $key ] ) && !isset($_SERVER['HTTP_REFERER'] )){ throw new Exception('initPOST: security failed.');
}
if( isset($_POST[$key]) && !$this->refererIsLocal() ){ throw new Exception('initPOST: security failed.');
}
}
}
}
}
Demo:
$sec= new security_request();
$sec->initGET(array('delete', 'edit', 'add')); $sec->initPOST(array('add', 'edit', 'id', 'captcha'));