As the first security door, made captcha to prevent brutal action from a robot. How do I create one? Find out more here.
Re-typing a line of random characters for reasons of security seems to be mandatory that you must do when making the registration process for membership online. Not only in the registration form online, similar things can be encountered during the process online transactions in which the transmitted data is data that is crucial.
Random character string that you need to reset the type is known by the term captcha. Captcha is made with the assumption that only men can see the whole picture and identify the characters shown for a reset. This is to prevent the brutal actions carried out auto-generated by script or robot system in disarray a website.
Programmer website utilizing GD library in PHP script that converts them to create a line of random characters into an image. This article will discuss how to make a captcha system by using GD library functions.
About PHP-GD
PHP is not only used to process text and numeric data that are then displayed in HTML format, but can also be used to generate and process images with a variety of formats (including JPEG, GIF, PNG) To do that, you can take advantage of image processing functions that are in the GD library.
GD library that PHP scripts run with the term is often called the PHP-GD. In addition to the basic images, such as point, line, and writing, you can also use the PHP-GD to manipulate the image or the image in accordance with the meaning you want to submit.
Enabling GD Library
Before processing an image with PHP-GD, you should make sure that the server you use supports the use of GD library functions. There are several ways you can do to see the GD library on the server you use. One is by using the function phpinfo ()
Phpinfo();
?>
Function phpinfo () will show a lot of information about the condition of PHP in your server. Included in the information on the status of PHP libraries (known as term extension) that can be used. You can find out the status of the GD library in the search for information about the PHP Information.
If there is information on the GD (GD Support: Enabled) then the server that you use already support the use of GD library first before you start the experiment with image-processing PHP script.
To activate the GD library, you simply open the file php.ini (PHP Configuration File) and make a few changes to remove the sign ";" (semicolon) at the line "extension = php_gd2.dll"
How the above is quite easy to do because the server that you use the server is localhost which is your computer. Then, what if you use a service provider's server hosting service website? Of course you do not have access rights to modify the configuration file is.
The majority of website hosting service providers have facilities to include PHP-GD on services, so you do not need to activate the GD library to use them. However, if the facility is not available, you can still activate the GD library to use the following simple script:
if(!extension_loaded('gd')){
if(strtoupper(substr(PHP_OS, 3)) == "WIN"){
dl('php_gd2.dll');
}Else{
dl('gd.so');
}
}
?>
Initially, the script above will make the checking of the extension 'gd' on the server. If not active, the function dl () will load the library on the server in accordance with the operating system used by the server. For servers with a base Windows OS, akan load file 'php_gd2.dll' while server with LINUX or UNIX base akan load file 'gd.so'
Make a Captcha with PHP-GD
After ensuring that the server that is used to support the use of PHP-GD, you can start the experiment with image processing in PHP
One application that is made by using PHP-GD captcha is. As discussed previously, a captcha is an image that shows the combination of random characters. The images generated by the captcha generator in which there is a function of PHP-GD
This time you will learn to create captcha and consists of three main files, namely image.php, action.php, and index.php
Image.php file will act as a captcha generator produce fruit 7 random characters. Meanwhile, file action.php function as a captcha validator akan test visitor response to the generated captcha. The file index.php is a form that will display the captcha and ask captcha response to it.
Captcha Generator
To create a captcha, first must determine what combination of characters that will be displayed. You can create a random character generator from the hash function md5 ()
//captcha generator
//make random character
$random character = md5(rand(0.999));
$secret_code = substr(random_character, 17, 7);
//save secret code as session
session_start ();
$ _SESSION ["secret_code"] = $secret_code;
?>
The process is further mengonversi characters into an image with PHP-GD. Typically, a captcha is created with a specific effect any posts with the intent to make the robot recognize karakteryang displayed. However, it would be a mistake if the characters that appear very difficult to recognize, even though human.
There are many ways to make the effect any posts on the captcha. In addition to using the algorithm to manipulate the image, any posts effects can also be generated from the election with a certain type of letter style that is quite unique. This time, the effect any posts captcha taken from the selection of a particular case can still be read if only by men.
You can use the function ImageTTFText () to put any posts in the image on PHP-GD. ImageTTFText function () will take a string which is the name of the file of this type of letter that will be used. File the letter should be placed in the same folder with a captcha generator.
Captcha script generator more have below:
//captcha generator
//make random character
$random_character = md5(rand (0.999));
$secret_code = substr($ random_character, 17, 7);
//save secret code as session
session_start();
$ _SESSION["Secret_code"] = $ secret_code;
//make image area
$width = 170;
$height = 70;
$image = ImageCreate($width, $height);
//allocate color that will be used
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$green = ImageColorAllocate($image, 0, 255, 0);
//allocate black color background
ImageFill($image, 0, 0, $ black);
//display the secret code on image
ImageTTFText($image, 30, 7, 10, 60, $green,"SoulMission.TTF", $secret_code);
//provide additional particles form a line
ImageRectangle($image, 0, 0, $width-1, $height-1, $green);
ImageLine($image, 0, $ height / 2, $ width, $ height / 2, $ green);
ImageLine($image, $width/2, 0, $width/2, $height, $green);
//member on a message browser about type of file
Header("Content-Type:image/jpeg");
//output as image
ImageJPEG($image);
//clean up memory
ImageDestroy ($image);
?>
In the script above, ImageCreate function (width, height) will create a blank image with the width and height as a place to put some components captcha image. In addition to these functions, there are other functions you can use to create an image, namely ImageCreateTrueColor (width, height) Although the parameters have the same, the two functions have a difference in the capacity of colors that can be used.
ImageCreate function (width, height) can be used to process images with up to 256 colors. This function is suitable to process images in the format. "Gif" Meanwhile, the function ImageCreateTrueColor (width, height) can be used to process images with color depth up to 32-bit.
After determining the image area, the program will be allocated a number of colors that will be charged at $ image. ImageColorAllocate function (resource image, int red, int green, int blue) will be allocated a color that will apply to the image resource with a combination of colors red, green, blue. Int value that can be provided in the red, green, and blue is in between 0-255 (color palette).
Once allocated a color, you can put color in the image resource through many ways, one of which is ImageFill (resource image, int x, inty, int color) function has four parameters, namely resource image, int x, int y, int and color. If the function will be used to color the entire member area image resource, then you simply write down the coordinates (0, 0) with the int color is already allocated in advance.
The next step is to put the text in the form of random combinations of characters as characters captcha. To put the text on the image, you can use the ImageString () function and ImageTTFText ().
ImageString function () has six parameters, namely resource image, int fontNumber, int x, int y, string text, int, and color. Meanwhile, the function ImageTTFText () has eight parameters, namely resource image, int size, int angle, int x, int y, int color, string fontFile, and text string. The main difference on the second function is the diversity of the letter / character that can be displayed. In the script above, we use the function ImageTTFText () to retrieve the resource type of the form of additional letters that have been provided a unique past.
After placing unique characters in the picture, you can add additional particles to sophisticated robots. Captcha project at this time, particles are used to form two lines are mutually perpendicular and have the picture in the middle. The colors have the same character shown.
To create a line, you can use the function ImageLine (resource image, int x1, int y1, int x2, int y2, int color) parameters x1 and y1 are the coordinates for the beginning of a line drawing, while the parameter x2 and y2 are the coordinates of the point indicates from the last line that you make.
The script also uses the above function ImageRectangle (resource image, int x1, int y1, int x2, int y2, int color) to make the borderline of the captcha image is. Similar to the function ImageLine (), parameter int x1, int y1 are the starting point to create a square followed by int x2, int y2, which is the end point the image is built.
Then the program will inform the browser that the file is an image file image.php with type jpeg. After that, the function ImageJPEG (resource image) will show the results of the end of the image that you created earlier. To note, at the time the program runs, the image processing done by the GD library in memory so that it needed a function that displays the overall results of processing these images. After the results are displayed, you can clean with a memory function ImageDestroy (resource image) as in the program.
Captcha validator
After creating captcha generator, you must create a captcha validator to validate the responses given to the visitors. Captcha validator will read the code stored in the secret session at the code generated by the captcha generator. Secret code will be compared with the responses of visitors who make a transaction.
Here is a script for captcha validator:
Form For Captcha
After creating captcha captcha generator and validator, you must create a form that will display a captcha that you make. In form, there are at least three elements, the captcha image, textbox, and button. To avoid rewriting the URL, you should use the POST method to send data from form to captcha validator
After that, you can perform testing in the captcha that you have created.
Re-typing a line of random characters for reasons of security seems to be mandatory that you must do when making the registration process for membership online. Not only in the registration form online, similar things can be encountered during the process online transactions in which the transmitted data is data that is crucial.
Random character string that you need to reset the type is known by the term captcha. Captcha is made with the assumption that only men can see the whole picture and identify the characters shown for a reset. This is to prevent the brutal actions carried out auto-generated by script or robot system in disarray a website.
Programmer website utilizing GD library in PHP script that converts them to create a line of random characters into an image. This article will discuss how to make a captcha system by using GD library functions.
About PHP-GD
PHP is not only used to process text and numeric data that are then displayed in HTML format, but can also be used to generate and process images with a variety of formats (including JPEG, GIF, PNG) To do that, you can take advantage of image processing functions that are in the GD library.
GD library that PHP scripts run with the term is often called the PHP-GD. In addition to the basic images, such as point, line, and writing, you can also use the PHP-GD to manipulate the image or the image in accordance with the meaning you want to submit.
Enabling GD Library
Before processing an image with PHP-GD, you should make sure that the server you use supports the use of GD library functions. There are several ways you can do to see the GD library on the server you use. One is by using the function phpinfo ()
Phpinfo();
?>
Function phpinfo () will show a lot of information about the condition of PHP in your server. Included in the information on the status of PHP libraries (known as term extension) that can be used. You can find out the status of the GD library in the search for information about the PHP Information.
If there is information on the GD (GD Support: Enabled) then the server that you use already support the use of GD library first before you start the experiment with image-processing PHP script.
To activate the GD library, you simply open the file php.ini (PHP Configuration File) and make a few changes to remove the sign ";" (semicolon) at the line "extension = php_gd2.dll"
How the above is quite easy to do because the server that you use the server is localhost which is your computer. Then, what if you use a service provider's server hosting service website? Of course you do not have access rights to modify the configuration file is.
The majority of website hosting service providers have facilities to include PHP-GD on services, so you do not need to activate the GD library to use them. However, if the facility is not available, you can still activate the GD library to use the following simple script:
if(!extension_loaded('gd')){
if(strtoupper(substr(PHP_OS, 3)) == "WIN"){
dl('php_gd2.dll');
}Else{
dl('gd.so');
}
}
?>
Initially, the script above will make the checking of the extension 'gd' on the server. If not active, the function dl () will load the library on the server in accordance with the operating system used by the server. For servers with a base Windows OS, akan load file 'php_gd2.dll' while server with LINUX or UNIX base akan load file 'gd.so'
Make a Captcha with PHP-GD
After ensuring that the server that is used to support the use of PHP-GD, you can start the experiment with image processing in PHP
One application that is made by using PHP-GD captcha is. As discussed previously, a captcha is an image that shows the combination of random characters. The images generated by the captcha generator in which there is a function of PHP-GD
This time you will learn to create captcha and consists of three main files, namely image.php, action.php, and index.php
Image.php file will act as a captcha generator produce fruit 7 random characters. Meanwhile, file action.php function as a captcha validator akan test visitor response to the generated captcha. The file index.php is a form that will display the captcha and ask captcha response to it.
Captcha Generator
To create a captcha, first must determine what combination of characters that will be displayed. You can create a random character generator from the hash function md5 ()
//captcha generator
//make random character
$random character = md5(rand(0.999));
$secret_code = substr(random_character, 17, 7);
//save secret code as session
session_start ();
$ _SESSION ["secret_code"] = $secret_code;
?>
The process is further mengonversi characters into an image with PHP-GD. Typically, a captcha is created with a specific effect any posts with the intent to make the robot recognize karakteryang displayed. However, it would be a mistake if the characters that appear very difficult to recognize, even though human.
There are many ways to make the effect any posts on the captcha. In addition to using the algorithm to manipulate the image, any posts effects can also be generated from the election with a certain type of letter style that is quite unique. This time, the effect any posts captcha taken from the selection of a particular case can still be read if only by men.
You can use the function ImageTTFText () to put any posts in the image on PHP-GD. ImageTTFText function () will take a string which is the name of the file of this type of letter that will be used. File the letter should be placed in the same folder with a captcha generator.
Captcha script generator more have below:
//captcha generator
//make random character
$random_character = md5(rand (0.999));
$secret_code = substr($ random_character, 17, 7);
//save secret code as session
session_start();
$ _SESSION["Secret_code"] = $ secret_code;
//make image area
$width = 170;
$height = 70;
$image = ImageCreate($width, $height);
//allocate color that will be used
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$green = ImageColorAllocate($image, 0, 255, 0);
//allocate black color background
ImageFill($image, 0, 0, $ black);
//display the secret code on image
ImageTTFText($image, 30, 7, 10, 60, $green,"SoulMission.TTF", $secret_code);
//provide additional particles form a line
ImageRectangle($image, 0, 0, $width-1, $height-1, $green);
ImageLine($image, 0, $ height / 2, $ width, $ height / 2, $ green);
ImageLine($image, $width/2, 0, $width/2, $height, $green);
//member on a message browser about type of file
Header("Content-Type:image/jpeg");
//output as image
ImageJPEG($image);
//clean up memory
ImageDestroy ($image);
?>
In the script above, ImageCreate function (width, height) will create a blank image with the width and height as a place to put some components captcha image. In addition to these functions, there are other functions you can use to create an image, namely ImageCreateTrueColor (width, height) Although the parameters have the same, the two functions have a difference in the capacity of colors that can be used.
ImageCreate function (width, height) can be used to process images with up to 256 colors. This function is suitable to process images in the format. "Gif" Meanwhile, the function ImageCreateTrueColor (width, height) can be used to process images with color depth up to 32-bit.
After determining the image area, the program will be allocated a number of colors that will be charged at $ image. ImageColorAllocate function (resource image, int red, int green, int blue) will be allocated a color that will apply to the image resource with a combination of colors red, green, blue. Int value that can be provided in the red, green, and blue is in between 0-255 (color palette).
Once allocated a color, you can put color in the image resource through many ways, one of which is ImageFill (resource image, int x, inty, int color) function has four parameters, namely resource image, int x, int y, int and color. If the function will be used to color the entire member area image resource, then you simply write down the coordinates (0, 0) with the int color is already allocated in advance.
The next step is to put the text in the form of random combinations of characters as characters captcha. To put the text on the image, you can use the ImageString () function and ImageTTFText ().
ImageString function () has six parameters, namely resource image, int fontNumber, int x, int y, string text, int, and color. Meanwhile, the function ImageTTFText () has eight parameters, namely resource image, int size, int angle, int x, int y, int color, string fontFile, and text string. The main difference on the second function is the diversity of the letter / character that can be displayed. In the script above, we use the function ImageTTFText () to retrieve the resource type of the form of additional letters that have been provided a unique past.
After placing unique characters in the picture, you can add additional particles to sophisticated robots. Captcha project at this time, particles are used to form two lines are mutually perpendicular and have the picture in the middle. The colors have the same character shown.
To create a line, you can use the function ImageLine (resource image, int x1, int y1, int x2, int y2, int color) parameters x1 and y1 are the coordinates for the beginning of a line drawing, while the parameter x2 and y2 are the coordinates of the point indicates from the last line that you make.
The script also uses the above function ImageRectangle (resource image, int x1, int y1, int x2, int y2, int color) to make the borderline of the captcha image is. Similar to the function ImageLine (), parameter int x1, int y1 are the starting point to create a square followed by int x2, int y2, which is the end point the image is built.
Then the program will inform the browser that the file is an image file image.php with type jpeg. After that, the function ImageJPEG (resource image) will show the results of the end of the image that you created earlier. To note, at the time the program runs, the image processing done by the GD library in memory so that it needed a function that displays the overall results of processing these images. After the results are displayed, you can clean with a memory function ImageDestroy (resource image) as in the program.
Captcha validator
After creating captcha generator, you must create a captcha validator to validate the responses given to the visitors. Captcha validator will read the code stored in the secret session at the code generated by the captcha generator. Secret code will be compared with the responses of visitors who make a transaction.
Here is a script for captcha validator:
Form For Captcha
After creating captcha captcha generator and validator, you must create a form that will display a captcha that you make. In form, there are at least three elements, the captcha image, textbox, and button. To avoid rewriting the URL, you should use the POST method to send data from form to captcha validator
After that, you can perform testing in the captcha that you have created.
Comments
Post a Comment