<?php2.index.php
session_start();
class mathcaptcha
{
private $bil1;
private $bil2;
private $operator;
function initial(){
$listoperator = array('+', '-', 'x');
$this->bil1 = rand(0, 99);
$this->bil2 = rand(0, 99);
$this->operator = $listoperator[rand(0, 2)];
}
function generatekode(){
$this->initial();
if ($this->operator == '+') $hasil = $this->bil1 + $this->bil2;
else if ($this->operator == '-') $hasil = $this->bil1 - $this->bil2;
else if ($this->operator == 'x') $hasil = $this->bil1 * $this->bil2;
$_SESSION['kode'] = $hasil;
}
function showcaptcha(){
echo "Hasil dari <big><b style=color:#0ec4f7;>".$this->bil1." ".$this->operator." ".$this->bil2."</b></big> ? ";
}
function resultcaptcha(){
return $_SESSION['kode'];
}
}
?>
<?php
include 'class-captcha.php';
$captcha1 = new mathcaptcha();
$captcha1->generatekode();
$captcha1->showcaptcha();
source untuk validasi........
include 'class-captcha.php';
$captcha1 = new mathcaptcha();
$kode = $_POST['kode'];
else
if ($captcha1 -> resultcaptcha() == $kode){
//-----------pesan ok
}else {
//------------pesan error
}
?>
Hanyep............................................................!!!





0 komentar:
Posting Komentar