{"id":300620,"date":"2020-03-23T21:00:35","date_gmt":"2020-03-23T21:00:35","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=300620"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-03-23T21:00:35","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=300620","title":{"rendered":"\u041a\u0430\u043f\u0447\u0430 \u0434\u043b\u044f codeigniter 4"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/493752\/\">\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c! \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0441\u0442\u0430\u0442\u044c\u0438, \u0432 \u043d\u0435\u0439 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043e\u0431\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0435\u0439 \u043a\u0430\u043f\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0440\u0430\u0432\u043a\u0430\u043c\u0438. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u0445 \u043f\u043e\u0441\u0442\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/120615\/\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 CAPTCHA \u0441\u0432\u043e\u0438\u043c\u0438 \u0440\u0443\u043a\u0430\u043c\u0438<\/a>.<\/p>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 GD \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432 PHP. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 gd_info(). \u0412 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e 2.1.0 \u0438 PHP 7.4.3, \u0447\u0442\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 PHP7 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f.<\/p>\n<h2>\u041b\u043e\u0433\u0438\u043a\u0430<\/h2>\n<p>  \u041a\u0430\u043a\u0443\u044e \u043a\u0430\u043f\u0447\u0443 \u044f \u0445\u043e\u0447\u0443 \u0432\u0438\u0434\u0435\u0442\u044c? \u0422\u0430\u043a\u0443\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043c\u043d\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u043f\u0440\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043c\u043e\u0435\u043c \u0441\u0430\u0439\u0442\u0435 \u0441 codeigniter 4.<\/p>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0441 \u043a\u043e\u0434\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043f\u043a\u0443, \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 base64 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e. <br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430<\/h2>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<pre><code class=\"php\">public function generate_code() {         srand((float) microtime() * 1000000);         $chars = 'ABDEFHKNRSTYZabdefhknrstyz23456789'; \/\/ \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432         $length = rand(5, 7); \/\/ \u0434\u043b\u0438\u043d\u0430 \u043a\u0430\u043f\u0447\u0438         $numChars = strlen($chars);          $str = '';         for ($i = 0; $i &lt; $length; $i++) {             $str .= $chars[rand(0, $numChars - 1)];         }         $array_mix = preg_split('\/\/', $str, -1, PREG_SPLIT_NO_EMPTY);         shuffle($array_mix);         delete_cookie('cap'); \/\/ \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043a\u0443\u043a, \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0441\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434         set_cookie('cap', md5(implode(&quot;&quot;, $array_mix)), self::$_code_time); \/\/ \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u043a\u0443\u043a \u043a\u043e\u0434 \u0432 md5 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f _code_time         return implode(&quot;&quot;, $array_mix);     } <\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0448\u0440\u0438\u0444\u0442\u044b \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043f\u043e\u0442\u043e\u043c\u0443 \u043d\u0430\u0434\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0437\u043d\u0430\u043a\u043e\u0432, \u0438\u043b\u0438 \u043d\u0430 \u0441\u0430\u043c\u0438 \u0448\u0440\u0438\u0444\u0442\u044b, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0442\u0430\u043a\u0438\u043c\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438 \u043a\u0430\u043a \u00abZ\u00bb \u0438 \u00abz\u00bb, \u00abX\u00bb \u0438 \u00abx\u00bb, \u00abI\u00bb \u0438 \u00abl\u00bb \u0438 \u0442.\u0434., \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u0441\u043a\u0430\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0432\u043e\u0434 \u043a\u0430\u043f\u0447\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u044b\u043c. <\/p>\n<p>  \u041e\u0431\u044a\u044f\u0432\u043b\u044f\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043f\u043e\u043b\u044f.<\/p>\n<pre><code class=\"php\">public static $width = 220; \/\/ \u0448\u0438\u0440\u0438\u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0432 \u043f\u0438\u043a\u0441\u0435\u043b\u044f\u0445 public static $height = 120; \/\/ \u0432\u044b\u0441\u043e\u0442\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 public static $fonts_num = 4; \/\/ \u0447\u0438\u0441\u043b\u043e \u0448\u0440\u0438\u0444\u0442\u043e\u0432 \u0432 \u043f\u0430\u043f\u043a\u0435 \/public\/fonts\/ private static $_code_time = 180; \/\/ \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043a\u0443\u043a\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445. <\/code><\/pre>\n<p>  \u0413\u043e\u0442\u043e\u0432\u043b\u044e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0444\u043e\u043d\u043e\u0432 \u0438 \u0448\u0443\u043c\u043e\u0432 (\u043f\u043e\u043b\u043d\u044b\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u0432 \u043a\u043e\u043d\u0446\u0435).<\/p>\n<pre><code class=\"php\">\/**      * \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043b\u0438\u043d\u0438\u0438 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.      *      * $mode == &quot;parallel&quot;, \u0440\u0438\u0441\u0443\u0435\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043b\u0438\u043d\u0438\u0438      * $max \u2014 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043b\u0438\u043d\u0438\u0439      *\/ private function _add_line($img, $mode = '', $max = 100) {     for ($i = 0; $i &lt; rand(0, $max); $i++) {         $color = imagecolorallocate($img, rand(80, 150), rand(80, 150), rand(80, 150));         if ($mode === 'parallel') {             $r1 = rand(0, self::$width);             $r2 = rand(0, self::$width);             imageline($img, $r1, $r1, $r2, $r1, $color);             imageline($img, $r1, $r2, $r1, rand(0, 220), $color);         } else {             imageline($img, rand(0, self::$width), rand(0, self::$width), rand(0, self::$width), rand(0, self::$width), $color);         }     } }  private function _add_poly($img) { \/\/ \u0440\u0438\u0441\u0443\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043c\u043d\u043e\u0433\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u0438     $points = [];     for ($i = 0; $i &lt; 10; $i++) {         array_push($points, rand(0, self::$width * 2));     }     $color = imagecolorallocate($img, rand(80, 190), rand(80, 190), rand(80, 190));     imageFilledPolygon($img, $points, 5, $color); }  \/**      * \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0441\u043a\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.      *      * $xn \u0438 $yn \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0446\u0432\u0435\u0442\u0430 \u043f\u0438\u043a\u0441\u0435\u043b\u044f. \u0415\u0441\u043b\u0438 \u043e\u043d\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b, \u0438\u0441\u043a\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u0442\u0430\u0435\u0442 \u0432\u0438\u0434, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 \u0448\u0443\u043c. \u0415\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435, \u0442\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0438\u0441\u043a\u0430\u0436\u0430\u0435\u043c\u044b\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 &quot;\u0432\u044b\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442\u0441\u044f&quot;.      * $mode \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 ('normal').      *\/ private function _set_glitch_color($image, $xn = 0, $yn = 0, $mode = 'normal') {     $start = rand(self::$height \/ 2, self::$height \/ 2 - self::$height \/ 4);     $finish = $start + rand(5, 15);     for ($x = 0; $x &lt; self::$width - 1; $x++) {         for ($y = 0; $y &lt; self::$height - 1; $y++) {             if ($mode != 'normal') {                 $xn = rand(0, 1);                 $yn = rand(0, 1);             } else {                 $finish = $start + 3;             }             if ($y &gt; $start && $y &lt; $finish) {                 imagesetpixel($image, $x + $xn, $y + $yn, imagecolorat($image, $x, $y));             }         }     } } <\/code><\/pre>\n<p>  \u041f\u043e\u0447\u0442\u0438 \u0433\u043e\u0442\u043e\u0432\u043e. \u041f\u0438\u0448\u0435\u043c \u0441\u0435\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435.<\/p>\n<pre><code class=\"php\">private function _add_text($img, $text) {     $x = rand(10,20); \/\/ \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0439 \u043e\u0442\u0441\u0442\u0443\u043f \u043f\u043e X \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u0431\u0443\u043a\u0432\u044b.     for ($i = 0; $i &lt; strlen($text); $i++) {         $text_color = imagecolorallocate($img, rand(150, 250), rand(150, 250), rand(150, 250));         imagettftext($img, rand(35, 40), rand(0, 10) - rand(0, 10), $x, rand(55, 95), $text_color, 'fonts\/' . rand(1, self::$fonts_num) . &quot;.ttf&quot;, $text[$i]); \/\/ \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0431\u0443\u043a\u0432\u044b \u0448\u0440\u0438\u0444\u0442 \u043e\u0442 1.ttf \u0434\u043e *self::$fonts_num*.ttf         $x += rand(25, 35);     } }<\/code><\/pre>\n<p>  \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<pre><code class=\"php\">public function img_code($code) {     $image = imagecreatetruecolor(self::$width, self::$height);     imageantialias($image, true);     $rand_color = imagecolorallocate($image, rand(50, 120), rand(50, 120), rand(50, 120));     imagefilledrectangle($image, 0, 0, self::$width, self::$height, $rand_color);     $this-&gt;_add_rand_bg($image); \/\/ \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0444\u043e\u043d \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435     $this-&gt;_add_text($image, $code);      $this-&gt;_add_glitch($image, 'normal');     $this-&gt;_add_glitch($image, 'boom');     $this-&gt;_add_line($image, 'rand', 200); \/\/ \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043b\u0438\u043d\u0438\u0438 \u043f\u043e\u0432\u0435\u0440\u0445 \u043a\u043e\u0434\u0430     $file = 'temp\/' . md5($code) . &quot;.png&quot;;      imagepng($image, $file); \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443     imagedestroy($image);     $res = base64_encode(file_get_contents($file)); \/\/ \u0431\u0435\u0440\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0432 base64()     unlink($file); \/\/ \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b     return $res; }  public function check($tested) {     $cap = get_cookie('cap');     $r['error'] = '';     if (!$cap) { \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0436\u0438\u0437\u043d\u0438 \u043a\u0443\u043a\u0430         $r['error'] = '\u0421\u0440\u043e\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043e\u0434\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u0442\u0435\u043a.';     } elseif (strcmp($tested, $cap)) {         $r['error'] = '\u041a\u043e\u0434\u044b \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442.';     }     delete_cookie('cap'); \/\/ \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043a\u0443\u043a \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435     return $r; } <\/code><\/pre>\n<p>  <\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>  \u0412 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u0445 \u0433\u043e\u0442\u043e\u0432\u0438\u043c \u043a\u0430\u043f\u0447\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"php\">public function __construct() {     ...     $this-&gt;captcha = new \\App\\Libraries\\Captcha();     ... }  public function some_function() {     ...     $data['captcha'] = $this-&gt;captcha-&gt;img_code( $this-&gt;captcha-&gt;generate_code() );     return view('page\/template', $data); }  public function recaptcha(){ \/\/ \u0434\u043b\u044f ajax-\u0437\u0430\u043f\u0440\u043e\u0441\u0430     return $this-&gt;captcha-&gt;img_code( $this-&gt;captcha-&gt;generate_code() ); } <\/code><\/pre>\n<p>  \u0412 \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u043e\u043a\u0435\u043d \u0438 \u043a\u043d\u043e\u043f\u043a\u0443 \u0434\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438:<\/p>\n<pre><code class=\"plaintext\">... &lt;input type=&quot;hidden&quot; name=&quot;&lt;?= csrf_token() ?&gt;&quot; value=&quot;&lt;?= csrf_hash() ?&gt;&quot; id=&quot;csrf&quot;\/&gt; ... &lt;img src=&quot;data:image\/png;base64,&lt;?= $captcha ?&gt;&quot; id=&quot;cap&quot; width=&quot;220&quot; height=&quot;120&quot;\/&gt; &lt;div id=&quot;ref&quot; onclick=&quot;recaptcha()&quot;&gt;\u2941&lt;\/div&gt; ... <\/code><\/pre>\n<p>  \u0414\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0440\u043e\u0443\u0442 \u0434\u043b\u044f ajax \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<pre><code class=\"php\">$routes-&gt;post('\/recap', 'AuthController::recaptcha');<\/code><\/pre>\n<p>  \u0418 \u0441\u0430\u043c ajax.<\/p>\n<pre><code class=\"javascript\">var numlog = 0; function recaptcha() {     if(numlog &lt;= 5){         $.ajax({             type: 'post',             url: '\/recap',             data: {csrf_token: $('#csrf').val()},             success: function (result) {                 numlog++;                 $('#cap').attr('src', &quot;data:image\/png;base64,&quot; + result + '');             }         });     }else{         $('#ref').css('display', 'none');     } }<\/code><\/pre>\n<p>  <\/p>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>  \u0428\u0443\u043c\u043d\u0430\u044f \u0446\u0432\u0435\u0442\u043e\u0432\u0430\u044f \u043f\u0430\u043b\u0438\u0442\u0440\u0430 \u0438 \u043d\u0430\u0431\u043e\u0440 \u0438\u0441\u043a\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u0430\u043f\u0447\u0438. \u041f\u043e\u0438\u0433\u0440\u0430\u0432 \u0441 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b.<\/p>\n<p>  \u0412\u0441\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b \u0432 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435 \u043d\u0430\u043a\u0438\u043d\u0443\u0432 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043f\u043e\u0440\u043e\u0433, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0432\u044b\u0434\u0435\u043b\u044f\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/8v\/ua\/ef\/8vuaef5uccgaxz06hvpqx30kuv4.png\"\/><\/p>\n<p>  \u0428\u0443\u043c \u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0438\u043d\u0438\u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c. \u041d\u043e \u0432\u044b\u0432\u043e\u0434 \u044f \u0434\u0435\u043b\u0430\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439: \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c, \u043e\u0434\u043d\u0430\u043a\u043e, \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432 \u0437\u0430\u0449\u0438\u0442\u0435 \u043e\u0442 \u0440\u044f\u0434\u043e\u0432\u044b\u0445 \u0431\u043e\u0442\u043e\u0432.<\/p>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/trtr7dr\/ci4\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435<\/a>. \u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f.<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/493752\/\"> https:\/\/habr.com\/ru\/post\/493752\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/493752\/\">\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c! \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0441\u0442\u0430\u0442\u044c\u0438, \u0432 \u043d\u0435\u0439 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043e\u0431\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0435\u0439 \u043a\u0430\u043f\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0440\u0430\u0432\u043a\u0430\u043c\u0438. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u0445 \u043f\u043e\u0441\u0442\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/120615\/\">\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 CAPTCHA \u0441\u0432\u043e\u0438\u043c\u0438 \u0440\u0443\u043a\u0430\u043c\u0438<\/a>.<\/p>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 GD \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432 PHP. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 gd_info(). \u0412 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e 2.1.0 \u0438 PHP 7.4.3, \u0447\u0442\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 PHP7 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f.<\/p>\n<h2>\u041b\u043e\u0433\u0438\u043a\u0430<\/h2>\n<p>  \u041a\u0430\u043a\u0443\u044e \u043a\u0430\u043f\u0447\u0443 \u044f \u0445\u043e\u0447\u0443 \u0432\u0438\u0434\u0435\u0442\u044c? \u0422\u0430\u043a\u0443\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043c\u043d\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u043f\u0440\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043c\u043e\u0435\u043c \u0441\u0430\u0439\u0442\u0435 \u0441 codeigniter 4.<\/p>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0441 \u043a\u043e\u0434\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043f\u043a\u0443, \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 base64 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-300620","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=300620"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300620\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=300620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=300620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=300620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}