if (rpHash($_POST[ 'realPerson' ]) == $_POST[ 'realPersonHash' ]) {
* This source code was highlighted with Source Code Highlighter .
if ($_POST[ 'In' ])== $_POST[ 'Out' ]) {
* This source code was highlighted with Source Code Highlighter .
$abc[ 'm' ] = array(1,1,7,1,1,2,2,2,6,2,7,2,1,3,3,3,5,3,7,3,1,4,4,4,7,4,1,5,7,5,1,6,7,6,1,7,7,7);
* This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- // all available alphabet
- $ alphanum = 'abcdefghijkmnopqrstuvxyz0123456789' ;
- // cycle, generate characters,
- // the number of loop iterations is equal to the number of characters in the string
- for ($ i = 0; $ i <$ the_number_of_letters; ++ $ i) {
- // randomly select a character
- $ letter = $ alphanum [intval (mt_rand (0, 33))];
- // create an array of characters $ array_str
- foreach ($ abc [$ letter] as $ key => $ val)
- // "correct" coordinates are arranged in the array
- array_push ($ array_str, ($ key% 2 == 0)? $ val + ($ i * 7): $ val);
- // the string itself is remembered
- $ di_captcha_str. = $ letter;
- }
* This source code was highlighted with Source Code Highlighter .
- // block length with tags
- // the number of tags in each row depends on this value
- // calculated by the formula number of cells + size of indent between the cells * 7
- // + double_size_cell - indent between characters
- // and all this is multiplied by the number of characters n
- $ ( '#DICaptchaPic' ) .css ( 'width' , ((((cell_size + 2) * 6) + (3 * cell_size) +1) * n));
- // variable to store the list of tags
- var html_p_tag = '' ;
- // loop traversal of the whole array with cells
- for (i = 1; i <= 7 * 7 * n; ++ i) {
- // if the cell is a multiple of seven, then it is extreme in the symbol
- // and therefore after it, indenting is required
- var style = (i% 7 == 0)? 'margin-right:' + 2 * cell_size + 'px;' : '' ;
- // if the cell is busy, then its background is black
- for (j = 0; j <data [1] .length; j + = 2) style + = (((i% (data [0] * 7) == 0)? (data [0] * 7): i% (data [0] * 7)) == data [1] [j] && Math.ceil (i / (data [0] * 7)) == data [1] [j + 1])? 'background-color: # 000;' : '' ;
- // closes the tag
- html_p_tag + = '<p' + ((style == '' )? '' : 'style = \' ' + style + ' \ '' ) + '>' ; }
* This source code was highlighted with Source Code Highlighter .
- function shuffle2 ($ array) {
- for ($ i = 0; $ i <count ($ array); $ i + = 2)
- for ($ j = count ($ array) -2; $ j> $ i; $ j - = 2)
- if (mt_rand (0, 1)> 0) {
- $ array [$ i] + = $ array [$ j]; $ array [$ j] = $ array [$ i] - $ array [$ j]; $ array [$ i] - = $ array [$ j];
- $ array [$ i + 1] + = $ array [$ j + 1]; $ array [$ j + 1] = $ array [$ i + 1] - $ array [$ j + 1]; $ array [$ i + 1] - = $ array [$ j + 1];
- }
- return $ array;
- }
* This source code was highlighted with Source Code Highlighter .
- // $ this-> noise is initialized when creating a class object
- // can take values ​​from 0 (no noise) to 10
- $ alphanum = 'abcdefghijkmnopqrstuvxyz0123456789' ;
- // main loop
- for ($ i = 0; $ i <$ this -> the_number_of_letters; ++ $ i) {
- $ letter = $ alphanum [intval (mt_rand (0, 33))];
- for ($ j = 0; $ j <count ($ this -> abc [$ letter]); $ j + = 2)
- // internal noise
- if (mt_rand (1, 100)> $ this -> noise * 5)
- array_push ($ this -> array_str, $ this -> abc [$ letter] [$ j] + ($ i * 7), $ this -> abc [$ letter] [$ j + 1]);
- // background noise
- for ($ j = 0; $ j <7 * 7 * ($ this -> noise / 20); ++ $ j) {
- array_push ($ this -> array_str, mt_rand (1, 7) + ($ i * 7), mt_rand (1, 7));
- }
- $ _SESSION [ 'di_captcha_str' ]. = $ Letter;
- }
- return $ this -> shuffle2 ($ this -> array_str);
* This source code was highlighted with Source Code Highlighter .
- // The constructor sets the length of the string of characters, the default is 6.
- // class methods:
- // shuffle2 () - shuffles the array.
- // set () - can change the values ​​of some class fields.
- // get () - returns an array of coordinates and puts the string itself into the session.
- // check () - accepts user-entered text and compares it with the string recorded in the session.
- namespace di;
- class captcha {
- private $ str, $ array_str = array (), $ abc = array (), $ the_number_of_letters = 6, $ noise = 1;
- function __construct ($ the_number_of_letters = 6) {
- $ this -> the_number_of_letters = $ the_number_of_letters;
- $ this -> abc [ 'a' ] = array (4,1,3,2,5,2,3,3,5,3,2,4,6,4,2,5,3,5,4 , 5,5,5,6,5,1,6,7,6,1,7,7,7);
- $ this -> abc [ 'b' ] = array (1,1,2,1,3,1,4,1,5,1,6,1,1,2,7,2,1,3,7 , 3,1,4,2,4,3,4,4,4,5,4,6,4,1,5,7,5,1,6,7,6,1,7,2,7 , 3,7,4,7,5,7,6,7);
- $ this -> abc [ 'c' ] = array (2,1,3,1,4,1,5,1,6,1,1,2,7,2,1,3,1,4,1 , 5,1,6,7,6,2,7,3,7,4,7,5,7,6,7);
- $ this -> abc [ 'd' ] = array (1,1,2,1,3,1,4,1,5,1,6,1,1,2,7,2,1,3,7 , 3,1,4,7,4,1,5,7,5,1,6,7,6,1,7,7,7,3,7,4,7,5,7,6,7 );
- $ this -> abc [ 'e' ] = array (1,1,2,1,3,1,4,1,5,1,6,1,7,1,1,2,1,3,1 4,2,4,3,4,4,4,1,5,1,6,1,7,2,7,3,7,4,7,5,7,7,7,7,7 );
- $ this -> abc [ 'f' ] = array (1,1,2,1,3,1,4,1,5,1,6,1,7,1,1,2,1,3,1 4,2,4,3,4,4,4,1,5,1,6,1,7);
- $ this -> abc [ 'g' ] = array (2,1,3,1,4,1,5,1,6,1,1,2,7,2,1,3,1,4,1 , 5,5,5,6,5,7,5,1,6,7,6,2,7,3,7,4,7,5,7,6,7);
- $ this -> abc [ 'h' ] = array (1,1,7,1,1,2,7,2,1,3,7,3,1,4,2,4,3,4,4 , 4,5,4,6,4,7,4,1,5,7,5,1,6,7,6,1,7,7,7);
- $ this -> abc [ 'i' ] = array (1,1,2,1,3,1,4,1,5,1,6,1,7,1,4,2,4,3,4 4,4,5,4,6,1,7,7,7,3,7,4,7,5,7,6,7,7,7);
- $ this -> abc [ 'j' ] = array (7,1,7,2,7,3,7,7,7,5,1,6,7,6,2,7,3,7,4 , 7,5,7,6,7);
- $ this -> abc [ 'k' ] = array (1,1,7,1,1,2,5,2,6,2,1,3,3,3,3,3,1,4,2 4,1,5,3,5,4,5,1,6,5,6,6,6,1,7,7,7);
- $ this -> abc [ 'l' ] = array (1,1,1,2,1,3,1,4,1,5,1,6,1,7,7,7,3,7,4 , 7,5,7,6,7,7,7);
- $ this -> abc [ 'm' ] = array (1,1,7,1,1,2,2,2,2,6,2,7,2,1,3,3,3,5,3,7 , 3,1,4,4,4,7,4,1,5,7,5,1,6,7,6,1,7,7,7);
- $ this -> abc [ 'n' ] = array (1,1,7,1,1,2,2,2,7,7,1,3,3,3,7,3,1,4,4 , 4,7,4,1,5,5,5,7,5,1,6,6,6,6,6,6,1,7,7,7);
- $ this -> abc [ 'o' ] = array (2,1,3,1,4,1,5,1,6,1,1,2,7,2,1,3,7,3,1 , 4,7,4,1,5,7,5,1,6,7,6,2,7,3,7,4,7,5,7,6,7);
- $ this -> abc [ 'p' ] = array (1,1,2,1,3,1,4,1,5,1,6,1,1,2,7,2,1,3,7 , 3,1,4,2,4,3,4,4,4,5,4,6,4,1,5,1,6,1,7);
- $ this -> abc [ 'q' ] = array (2,1,3,1,4,1,5,1,6,1,1,2,7,2,1,3,7,3,1 4,7,4,1,5,5,5,7,5,1,6,6,6,2,7,3,7,4,7,5,7,7,7);
- $ this -> abc [ 'r' ] = array (1,1,2,1,3,1,4,1,5,1,6,1,1,2,7,2,1,3,7 , 3,1,4,2,4,3,4,4,4,5,4,6,4,1,5,5,5,1,6,6,6,1,7,7,7 );
- $ this -> abc [ 's' ] = array (2,1,3,1,4,1,5,1,6,1,1,2,7,2,1,3,2,4,3 4,4,4,5,4,6,4,7,5,1,6,7,6,2,7,3,7,4,7,5,7,6,7);
- $ this -> abc [ 't' ] = array (1,1,2,1,3,1,4,1,5,1,6,1,7,1,4,2,4,3,4 4,4,5,4,6,4,7);
- $ this -> abc [ 'u' ] = array (1,1,7,1,1,2,7,2,1,3,7,3,1,4,7,4,1,5,7 , 5,1,6,7,6,2,7,3,7,4,7,5,7,6,7);
- $ this -> abc [ 'v' ] = array (1,1,7,1,1,2,7,2,2,3,3,3,2,4,6,4,3,5,5 5,3,6,5,6,4,7);
- $ this -> abc [ 'w' ] = array (1,1,7,1,1,2,7,2,1,3,7,3,1,4,4,4,7,4,1 5,3,5,5,5,7,5,1,6,2,6,6,6,6,6,6,1,7,7,7);
- $ this -> abc [ 'x' ] = array (1,1,7,1,2,2,6,2,3,3,5,3,4,4,3,5,5,5,2 , 6,6,6,1,7,7,7);
- $ this -> abc [ 'y' ] = array (1,1,7,1,2,2,6,2,3,3,5,3,4,4,4,5,4,6,4 , 7);
- $ this -> abc [ 'z' ] = array (1,1,2,1,3,1,4,1,5,1,6,1,7,1,6,2,5,3,4 4,3,5,2,6,1,7,7,7,3,7,4,7,5,7,6,7,7,7);
- $ this -> abc [ '0' ] = array (3,1,4,1,5,1,2,2,2,2,2,1,3,5,3,7,3,1,4,4 , 4,7,4,1,5,3,5,7,5,2,6,6,6,3,7,7,4,7,5,7);
- $ this -> abc [ '1' ] = array (4,1,3,2,4,2,2,3,3,3,4,4,4,5,4,6,1,7,7 , 7.3,7,4,7,5,7,6,7,7,7);
- $ this -> abc [ '2' ] = array (2,1,3,1,4,1,5,1,6,1,1,2,7,7,7,3,6,4,4 , 5,5,5,2,6,3,6,1,7,7,7,3,7,4,7,5,7,6,7,7,7);
- $ this -> abc [ '3' ] = array (2,1,3,1,4,1,5,1,6,1,1,2,7,7,7,3,5,4,6 , 4,7,5,1,6,7,6,2,7,3,7,4,7,5,7,6,7);
- $ this -> abc [ '4' ] = array (5,1,4,2,5,2,3,3,5,3,2,4,5,4,1,5,2,5,3 5,4,5,5,5,6,5,7,5,5,6,5,7);
- $ this -> abc [ '5' ] = array (1,1,2,1,3,1,4,1,5,1,6,1,7,1,1,2,1,3,2 , 3,3,3,4,3,5,3,6,3,7,4,7,5,1,6,7,6,2,7,3,7,4,7,5,7 , 6.7);
- $ this -> abc [ '6' ] = array (3,1,4,1,5,1,6,1,2,2,1,3,1,4,2,4,3,4,4 , 4,5,4,6,4,1,5,7,5,1,6,7,6,2,7,3,7,4,7,5,7,6,7);
- $ this -> abc [ '7' ] = array (1,1,2,1,3,1,4,1,5,1,6,1,7,1,6,2,5,3,4 , 4,3,5,2,6,1,7);
- $ this -> abc [ '8' ] = array (2,1,3,1,4,1,5,1,6,1,1,2,7,2,1,3,7,3,2 , 4,3,4,4,4,5,4,6,4,1,5,5,5,1,6,7,6,2,7,3,7,4,7,5,7 , 6.7);
- $ this -> abc [ '9' ] = array (2,1,3,1,4,1,5,1,6,1,1,2,7,2,1,3,7,3,2 , 4,3,4,4,4,5,4,6,4,7,4,7,5,6,6,2,7,3,7,4,7,5,7);
- }
- private function shuffle2 ($ array) {
- for ($ i = 0; $ i <count ($ array); $ i + = 2)
- for ($ j = count ($ array) -2; $ j> $ i; $ j - = 2)
- if (mt_rand (0, 1)> 0) {
- $ array [$ i] + = $ array [$ j]; $ array [$ j] = $ array [$ i] - $ array [$ j]; $ array [$ i] - = $ array [$ j];
- $ array [$ i + 1] + = $ array [$ j + 1]; $ array [$ j + 1] = $ array [$ i + 1] - $ array [$ j + 1]; $ array [$ i + 1] - = $ array [$ j + 1];
- }
- return $ array;
- }
- function set ($ name, $ val) {
- switch ($ name) {
- case 'the_number_of_letters' :
- $ this -> the_number_of_letters = ( int ) $ val;
- break ;
- case 'noise' :
- $ this -> noise = ( int ) $ val;
- break ;
- default :
- return false ;
- }
- return true ;
- }
- function get () {
- $ alphanum = 'abcdefghijkmnopqrstuvxyz0123456789' ;
- unset ($ _ SESSION [ 'di_captcha_str' ]);
- for ($ i = 0; $ i <$ this -> the_number_of_letters; ++ $ i) {
- $ letter = $ alphanum [intval (mt_rand (0, 33))];
- // foreach ($ this-> abc [$ letter] as $ key => $ val)
- // array_push ($ this-> array_str, ($ key% 2 == 0)? $ val + ($ i * 7): $ val);
- for ($ j = 0; $ j <count ($ this -> abc [$ letter]); $ j + = 2)
- if (mt_rand (1, 100)> $ this -> noise * 5)
- array_push ($ this -> array_str, $ this -> abc [$ letter] [$ j] + ($ i * 7), $ this -> abc [$ letter] [$ j + 1]);
- for ($ j = 0; $ j <7 * 7 * ($ this -> noise / 20); ++ $ j) {
- array_push ($ this -> array_str, mt_rand (1, 7) + ($ i * 7), mt_rand (1, 7));
- }
- $ _SESSION [ 'di_captcha_str' ]. = $ Letter;
- }
- return $ this -> shuffle2 ($ this -> array_str);
- }
- function check ($ in_string) {
- echo $ in_string. '|' . $ _ SESSION [ 'di_captcha_str' ];
- return (strtolower ($ in_string) == $ _SESSION [ 'di_captcha_str' ])? true : false ;
- }
- }
// index.php
//
session_start();
// THE_NUMBER_OF_LETTERS – ,
define( 'THE_NUMBER_OF_LETTERS' , 6);
// js , .
if (isset($_POST[ 'action' ]{14}) && $_POST[ 'action' ] == 'captcha_refresh' ) {
require 'phar://di_captcha.class.phar.gz/di_captcha.class.php' ;
$captcha = new di\captcha();
$captcha-> set ( 'noise' , 0);
echo json_encode(array(THE_NUMBER_OF_LETTERS, $captcha-> get ()));
} else {
? > <br> <! DOCTYPE html > <br> < html > <br> < head > <br> < meta charset ='utf-8' > <br> < title > Test </ title > <br> < link rel ='stylesheet' media ='all' href ='style.css' > <br> < script type ='text/javascript' src ='jquery-1.6.1.min.js' charset ='utf-8' ></ script > <br> src= 'script.js' charset= 'utf-8' > </ script > <br> </ head > <br> < body > <br> < p id ='Title' > -, ! </ p > <br> < p id ='Msg' > <br> <? php <br> if ( isset ($ _POST [ 'action' ]{ 11 }) &# && ; $ _POST [ 'action' ] == 'captcha_send' ) {;<br> require 'phar://di_captcha.class.phar.gz/di_captcha.class.php' ;<br> $ captcha = new di \ captcha ();<br> echo ($ captcha- > check($_POST['text_captcha']))?'- !':' , ...';<br> }<br> ? > <br> </ p > <br> < form action ='index.php' method ='post' > <br> < div id ='DICaptchaPic' ></ div > <br> < p style ='padding: 0 10px;' > <br> < input type ='text' name ='text_captcha' id ='text_captcha' value ='<?php echo $_POST[' text_captcha ']; ? > ' placeholder='6 ' >< br >< label for ='text_captcha' > *a- </ label > < ahref ='#' onclick ='di_captcha_refresh(); return false;' > </ a > <br> </ p > <br> < p style ='padding: 10px 0;' > <br> < input type ='hidden' name ='action' value ='captcha_send' /> <br> < input type ='submit' name ='submit' value ='' /> <br> </ p > <br> </ form > <br> </ body > <br> </ html > <br> <? php<br> } <br> * This source code was highlighted with Source Code Highlighter .
} $ ( '#DICaptchaPic' ) .html (html_p_tag); })} $ ( document ) .ready ( function () {$ ( '#DICaptchaPic' ) .css ( 'overflow' , 'hidden' ); $ ( '#DICaptchaPic' ) .css ( 'height' , (cell_size + 2) * 7); di_captcha_refresh (); $ ( '#DICaptchaPic' ) .click ( function () {di_captcha_refresh ();}); $ ( '#text_captcha' ) .focus ()}) * This source code was shared with Source Code Highlighter .
- / * script.js * /
- / * cell_size - cell size in pixels * /
- var cell_size = 3;
- function di_captcha_refresh () {
- $ .post ( './index.php' , {action: 'captcha_refresh' },
- function (data) {
- var data = eval (data);
- $ ( '#DICaptchaPic' ) .css ( 'width' , ((((cell_size + 2) * 6) + (3 * cell_size) +1) * data [0]));
- var html_p_tag = '' ;
- for (i = 1; i <= 7 * 7 * data [0]; ++ i) {
- var style = (i% 7 == 0)? 'margin-right:' + 2 * cell_size + 'px;' : '' ;
- for (j = 0; j <data [1] .length; j + = 2) style + = (((i% (data [0] * 7) == 0)? (data [0] * 7): i% (data [0] * 7)) == data [1] [j] && Math.ceil (i / (data [0] * 7)) == data [1] [j + 1])? 'background-color: # 000;' : '' ;
- html_p_tag + = '<p' + ((style == '' )? '' : 'style = \' ' + style + ' \ '' ) + '> '
Source: https://habr.com/ru/post/121794/