CAPTCHAor Captcha is a form of challange-response test used in computing to ensure that answers are not produced by a computer. This process usually involves a computer (server) that asks a user to complete a simple test that the computer can generate and evaluate. Because other computers can not solve CAPTCHA, any user who can provide the correct answer will be considered a human. Therefore, this test is sometimes referred to as the Turing back test, as it is administered by machines and intended for humans, as opposed to the standard Turing test that is normally administered by humans and intended for a machine. CAPTCHA generally uses letters and numbers from distorted images that appear on the screen.
CAPTCHA is primarily used to prevent automated software (bot) from performing the same actions as people signing up or logging on and forth. For example when signing up for a new email account, you will find a CAPTCHA at the bottom of the sign-up, This is actually to ensure that the form can only be populated by humans rather than automated software or bot computers. Try to imagine it is impossible for a bot to guess exactly the CAPTCHA produced
index.php
"
< !DOCTYPE html>
< html>
< head>
< title>HOW TO MAKE CAPTCHA USING PHP PROGRAMMING METHOD</title>
< link rel="stylesheet" type="text/css" href="style.css">
< /head>
< body>
< h1>HOW TO MAKE CAPTCHA USING PHP PROGRAMMING METHOD< /h1>
< div class="kotak">
<?php
if(isset($_GET['pesan'])){
if($_GET['pesan'] == "salah"){
echo "<p>Captcha tidak sesuai.</p>";
}
}
?>
<p>Enter Captcha</p>
<form action="periksa_captcha.php" method="post">
<table align="center">
<tr>
<td>Captcha</td>
<td><img src="captcha.php" alt="gambar" /> </td>
</tr>
<td>Enter captcha </td>
<td><input name="nilaiCaptcha" value=""/></td>
<tr>
<td><input type ="submit" value="Cek Captcha"></td>
</tr>
</table>
</form>
</div>
< /body>
< /html>
"
style.css
"
body{
font-family: "roboto";
background: #F4F4F4;
}
h1,p{
text-align: center;
}
.kotak{
margin: 10px auto;
background: #fff;
width: 400px;
padding: 20px 0px;
}
.kotak table tr td{
padding: 5px;
}
.kotak table tr td input{
padding: 5px;
font-size: 12pt;
}
"
captcha.php
"
<?phpsession_start();
header("Content-type: image/png");
$_SESSION["Captcha"]="";
$gbr = imagecreate(200, 50);
imagecolorallocate($gbr, 69, 179, 157);
$color = imagecolorallocate($gbr, 253, 252, 252);
$font = "BERNHC.ttf";
$ukuran_font = 20;
$posisi = 32;
for($i=0;$i<=5;$i++) {
$angka=rand(0, 9);
$_SESSION["Captcha"].=$angka;
$kemiringan= rand(20, 20);
imagettftext($gbr, $ukuran_font, $kemiringan, 8+15*$i, $posisi, $color, $font, $angka);
}
imagepng($gbr);
imagedestroy($gbr);
?>
"
periksa_captcha.php
"
< !DOCTYPE html>
< html>
< head>
< title>HOW TO MAKE CAPTCHA USING PHP PROGRAMMING METHOD< /title>
< link rel="stylesheet" type="text/css" href="style.css ">
< /head>
< body>
< h1>HOW TO MAKE CAPTCHA USING PHP PROGRAMMING METHOD</h1>
< div class="kotak">
<?php
session_start();
if($_SESSION["Captcha"]!=$_POST["nilaiCaptcha"]){
header("location:index.php?pesan=salah");
}else{
echo "<p>Your Captcha right</p>";
}
?>
< /div>
< /body>
< /html>
"
session_start();
"
"
header("Content-type: image/png");
"
"
session_start();
header("Content-type: image/png");
$_SESSION["Captcha"]="";
$gbr = imagecreate(200, 50);
imagecolorallocate($gbr, 69, 179, 157);
$color = imagecolorallocate($gbr, 253, 252, 252);
$font = "BERNHC.ttf";
$ukuran_font = 20;
$posisi = 32;
for($i=0;$i<=5;$i++) {
$angka=rand(0, 9);
$_SESSION["Captcha"].=$angka;
$kemiringan= rand(20, 20);
imagettftext($gbr, $ukuran_font, $kemiringan, 8+15*$i, $posisi, $color, $font, $angka);
}
imagepng($gbr);
imagedestroy($gbr);
"
"
for($i=0;$i<=5;$i++) {
$angka=rand(0, 9);
$_SESSION["Captcha"].=$angka;
$kemiringan= rand(20, 20);
imagettftext($gbr, $ukuran_font, $kemiringan, 8+15*$i, $posisi, $color, $font, $angka);
}
"
"
imagettftext($gbr, $ukuran_font, $kemiringan, 8+15*$i, $posisi, $color, $font, $angka);
"
"
$font = "Allura-Regular.otf";
"