📜 ⬆️ ⬇️

Rebus captcha


After reading the previous topics about captcha, I got the idea to make a rebus captcha. Of course, using it in real projects is not very correct, as the user will spend time solving the rebus, and you probably know how even annoying captcha letters sometimes get annoying.


Rebus


The rebus includes only one method, when a part of a word is represented as an image with a certain number of clipped letters at the beginning or at the end. In order for one image to have several variations, the following file system structure is used:
 images /
 |                  
 + - + [image_name] / +
 |  + - + [image_type_1]   
 |  |
 |  + - + [image_type_2]   
 |  |
 |  + - + ...
 |  |
 |  + - + [image_type_n]   
 |
 |
 |
 |   
 + - + [image_name] / +
 + - + [image_type_1]
 |
 + - + [image_type_2]
 |
 + - + ...
 |
 + - + [image_type_n]

For example, when compiling a rebus from the word “str ea m”, the program found a match of letters (parts of the word) with the image “h ea rt”, then the used image will be selected randomly from the folder “/ images / heart /”.

Match search


Matching works in the following way: enumerating parts of a hidden word, and searching for matching with words that are represented by images. The hidden word, for example habrahabr, is divided into parts as follows:
 habrahabr
 habrahab
 abrahabr
 habraha
 abrahab
 brahabr
 habrah
 abraha
 brahab
 rahabr
 habra
 abrah
 braha
 rahab
 ahabr
 habr
 abra
 brah
 raha
 ahab
 habr
 hab
 abr
 bra
 rah
 aha
 hab
 abr
 ha

The search takes place before the first match, after which the left and right parts of the word from the matched are highlighted, for which the search is also applied.
')

Using


$rebus = new rebus('path/to/image/folder'); 

The passed parameter is the path to the folder with images, the structure of which should be as described above.
Settings:


Image generation:
 $rebus->getImage($flag); 



Full code:
 <?php session_start(); include 'rebus.class.php'; $rebus = new rebus('images'); $rebus->captchaWordsArray = Array( 'tar', 'swap', 'sic', 'threat', 'bow', 'stream', 'steam', 'google', 'comet', 'comet', 'hot', 'wool', 'hell', 'twitter', 'chat', 'habrahabr', 'warlock', 'fold', 'soft', 'ripper', 'apple' ); $rebus->getImage(); 


Previous topics about captcha:

For writing the topic used: The editor of data tables from ASCII-graphics

The source can be downloaded here .
An example can be found here .

Source: https://habr.com/ru/post/122081/


All Articles