Friday, December 1, 2017

Captcha

How to Create Captcha using PHP


In this tutorial we will discuss How to Create Captcha Using PHP. Cahtcha which stands for Completely Automated Public Turing test to tell Computers and Humans Apart it's the endorsement of the test word entered from a sign-up form such as signing up for Gmail, Yahoo, Facebook, twitter, and else. While understanding other Captcha is according to English Wikipedia
In this tutorial we will create Captcha manually with PHP.

Captcha is actually easy to create because it only creates a function to generate random characters and then put it in the image. And save it in the form of a session or a particular variable.

But Captcha technology is not perfect yet, because Spammers could have cached the Captcha manually, and can also make software to solve Captcha with a certain degree of difficulty.

However, Captcha remains important for the website. Because it plays a role in reducing spam and incorrect form entries.
1.  Creating a Web Captcha Page
Open the text editor, in this tutorial using notepad ++, after that please type or directly copy the code / script below and save it with the name index.html.
<html>
<head>
<title>
Login Page
</ title>
</ head>
<body>
<fill in Your Username and Password </ b> </ p>
<! - Create Login Form ->
<! - specify an action if the form has been submitted ->
<form action = "hasil.php" method = "post">
<table border = "0" cellpadding = "0" cellspacing = "0" align = "center">
<tr>
<td> Username </ td>
<td> <input name = "username" value = "" maxlength = "10"> </ td>
</ tr>
<tr>
<td> Password </ td>
<td> <input type = "password" name = "password" value = "" maxlength = "10"> </ td>
</ tr>
<tr>
<td> Captcha </ td>
<! - we specify the location of the script generate the image ->
<td> <img src = "images.php" alt = "picture" /> </ td>
</ tr>
<td> Fill in the captcha </ td>
<td> <input name = "valueCaptcha" value = "" maxlength = "6" /> </ td>
<tr>
<td> <input type = "submit" value = "Submit"> </ td>
</ tr>
</ table>
</ form>
</ body>
</ html>
2.  Creating Captcha Generate Scripts
Create a new file in your text editor and name it image.php. image.php file must be a folder with index.html file. Here's the script or code in the Captcha generate.
<? php
// enable session
session_start ();
header ("Content-type: image / png");

// name the session named Captcha
$ _SESSION ["Captcha"] = "";

// specify the image size
$ gbr = imagecreate (200, 50);

// background image color
imagecolorallocate ($ gbr, 167, 218, 239);
$ red = imagecolorallocate ($ gbr, 128, 128, 128);
$ black = imagecolorallocate ($ gbr, 0,0,0);

// specify a font
$ font = "monaco.ttf";

// creates a random number and is displayed in the image
for ($ i = 0; $ i <= 5; $ i ++) {

// number of characters
$ number = rand (0, 9);
$ _SESSION ["Captcha"]. = $ Number;
$ angle = rand (-25, 25);
imagettftext ($ gbr, 20, $ angle, 8 + 15 * $ i, 25, $ black, $ font, $ number);

// shadow effect
imagettftext ($ gbr, 20, $ angle, 9 + 15 * $ i, 26, $ red, $ font, $ number);
}

// to create an image
imagepng ($ gbr);
imagedestroy ($ gbr);
?>
Page result of the website after we finish Creating Captcha Generate Scripts.




Captcha

How to Create Captcha using PHP In this tutorial we will discuss How to Create Captcha Using PHP. Cahtcha which stands for Completely Aut...