TUTORIAL || HOW TO MAKE CAPTCHA BY USING PHP PROGRAMMING METHOD
What Will I Learn?
- We will learn how to make captcha
- We will learn the working system from captcha
- We will learn medsign form, connect the captchaC
Requirements
- Xampp
- Application browser
- Text editor
Difficulty
- Intermediate
Tutorial Contents
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
- Now just we make a captcha, we need first is the form from the captcha itself here we will create a file with the name index.php
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>
"
- Next we design to beautify the view of index.php file using CSS with style.css
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;
}
"
- After both are done we will create a fil to display a captcha image that is by the name of captcha.php
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);
?>
"
- And finally we make checks for captcha that we make whether true or false.
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>
Program Explanation
- To create a captcha we need a php session so first enable php session.
"
session_start();
"
- Then give the following function to be gamabar with php
"
header("Content-type: image/png");
"
- Selanjutnya pada syntax berikutlah yang bertugas membuat gamabar dengan php
"
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);
"
- So the number of captchan we make randomly
"
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);
}
"
- Kemudian berikan text pada gambar captcha dengan pengaturan yang sudah terpisah ke dalam variable.
"
imagettftext($gbr, $ukuran_font, $kemiringan, 8+15*$i, $posisi, $color, $font, $angka);
"
- The following syntax includes a font file that will be visible on the captcha image.
"
$font = "Allura-Regular.otf";
"
- And copy the font file into captcha folder like this.
- after the file above everything is finished then now the kit run the program it will look like this
- then we enter the code captchanya and then we kli check capchat as follows
- and after the click button capcha check it will come out like this it if the code captcha true
- and the tutorial is completed good luck
Posted on Utopian.io - Rewarding Open Source Contributors
Source: https://www.malasngoding.com/cara-membuat-captcha-dengan-php/
Not indicating that the content you copy/paste is not your original work could be seen as plagiarism.
Some tips to share content and add value:
Repeated plagiarized posts are considered spam. Spam is discouraged by the community, and may result in action from the cheetah bot.
Creative Commons: If you are posting content under a Creative Commons license, please attribute and link according to the specific license. If you are posting content under CC0 or Public Domain please consider noting that at the end of your post.
If you are actually the original author, please do reply to let us know!
Thank You!
Your contribution cannot be approved because it does not follow the Utopian Rules, and is considered as plagiarism. Plagiarism is not allowed on Utopian, and posts that engage in plagiarism will be flagged and hidden forever.
Plagiarised from here.
You can contact us on Discord.
[utopian-moderator]