Ma classe antispam est-elle suffisante ?
Posté : 24 avr. 2009, 16:26
Bonjour,
Je me suis fait une petite classe antispam very light, super simple et j'aurais voulu savoir si elle était suffisante et un minimum efficace.
Pour son utilisation voilà ce qui se passe...
A l'initialisation du formulaire :
new antispam
antispam->generer
antispam->getQuestion pour afficher la question dans le label
antispam->getReponse pour stoker la réponse dans un input hidden
A l'envoi :
new antispam
antispam->verifier($POST reponseUser, $POST reponse)
Je me suis fait une petite classe antispam very light, super simple et j'aurais voulu savoir si elle était suffisante et un minimum efficace.
Pour son utilisation voilà ce qui se passe...
A l'initialisation du formulaire :
new antispam
antispam->generer
antispam->getQuestion pour afficher la question dans le label
antispam->getReponse pour stoker la réponse dans un input hidden
A l'envoi :
new antispam
antispam->verifier($POST reponseUser, $POST reponse)
<?php
class antispam{
private $question;
private $reponse;
private $reponseUser;
private function setReponseUser($value){
$this->reponseUser = md5($value);
}
public function getQuestion(){
return $this->question;
}
public function getReponse(){
return $this->reponse;
}
public function generer(){
$nb1 = rand(1,5);
$nb2 = rand(1,5);
$this->question = $nb1.' et '.$nb2.' ?';
$this->reponse = md5($nb1+$nb2);
}
public function verifier($reponseUser, $reponse){
// $reponseUser & reponse from $_POST
$this->setReponseUser($reponseUser);
$this->reponse = $reponse;
if($this->reponseUser != $this->reponse){
throw new Exception('Antispam : mauvaise réponse !');
}
}
}
?>