Código de PHP - EZcaptcha

Imágen de perfil
Val: 33
Ha aumentado su posición en 5 puestos en PHP (en relación al último mes)
Gráfica de PHP

EZcaptchagráfica de visualizaciones


PHP

Publicado el 26 de Abril del 2021 por Mario Antonio (2 códigos)
1.271 visualizaciones desde el 26 de Abril del 2021
Copie el archivo class_ezcaptcha.php en su servidor y reemplace "<ruta real a sus fuentes ttf>" por la URL real apuntando a los archivos de fuentes cambiando el nombre de las fuentes también si es necesario.

Incluya la etiqueta <catpcha> </captcha> en el archivo html en el lugar donde desea mostrar el captcha.

Incluya JQuery (cualquie versión) y agrege el siguiente fragmento de JavaScript al final del archivo html dentro de las etiquetas <script> </script>. Recuerde reemplazar "<urlto>" por la URL real que apunta al archivo class_ezcaptcha.php

1
2
3
4
(función () {$ .ajax ({url: "<urlto> class_ezcaptcha.php? getHtml = 1", éxito: función (resultado) {
      $ ("captcha"). html (resultado);
   }});
}) ();

Incluya el captcha param y su valor en su POST o GET param string cuando envíe la solicitud http del formulario.

Valide los parámetros en el código del lado del servidor usando algo como esto:
1
if ($ _ POST ['captcha']! = $ _ SESSION ['captcha_code']) {return "ERRORcaptcha | Captcha incorrecto";}

Valide los resultados en su archivo ajax / html después de enviar la solicitud http.

Probar el demo http://mchsoft.com/demos/ezcaptcha/ezcaptcha.html
Disfrútalo...
screen
captcha
captcha_code

1
estrellaestrellaestrellaestrellaestrella(2)

Publicado el 26 de Abril del 2021gráfica de visualizaciones de la versión: 1
1.272 visualizaciones desde el 26 de Abril del 2021
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

captcha
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
session_start();
class captcha{
    var $url;
    private function Captcha(){
        $_SESSION["captcha_code"]='';
        $random_alpha = md5(rand());
        $leng=rand(6,8);
        $captcha_code = substr($random_alpha, 0, $leng);
        $target_layer = imagecreatetruecolor($leng*10+10,34);
        $captcha_background = imagecolorallocate($target_layer, 255, 160, 119);
        imagefill($target_layer,0,0,$captcha_background);
        $captcha_text_color = imagecolorallocate($target_layer, 0, 0, 0);
        $grey = imagecolorallocate($target_layer, 128, 128, 128);
        $font='<path a tus TTF fonts>/VeraBd.ttf';
        $functions[0]=function ($code){return $code;};
        $functions[1]=function ($code){return strtoupper($code);};
        for($i=0;$i<strlen($captcha_code);$i++){
            $code=$functions[rand(0,1)]($captcha_code[$i]);
            $_SESSION["captcha_code"].=$code;
            $angl=array(0,15,-15);
            $ang=$angl[rand(0,2)];
            // Adding shadow...
            imagettftext($target_layer, 10, $ang, 7+$i*10, 22, $grey, $font, $code);
            // Adding text...
            imagettftext($target_layer, 10, $ang, 5+$i*10, 20, $captcha_text_color, $font, $code);
        }
        header("Content-type: image/jpeg");
        imagejpeg($target_layer);
    }
 
    private function setHtml(){
 
        return '
        <style>
            .btnRefresh{background-color:#8B8B8B;border:0;padding:7px 10px;color:#FFF;float:left;}
            .labelcaptcha{color:#FF0000;display:none;}
        </style>
        <div class="form-group has-feedback">
            <label class="labelcaptcha" for="captcha"></label><input type="text" autocomplete="off" name="captcha" id="captcha" class="form-control Captcha" placeholder="Captcha">
            <img id="captcha_code" src="'.$this->url.'">
            <button type="button" name="btnrefreshCaptcha" class="btnRefresh" onclick="refreshCaptcha();">Refresh Captcha</button>
        </div>'.$this->setJS();
    }
    private function setJS(){
       return "
        <script>
            $(\"#captcha\").blur(function(){
                $(\"#captcha\").css('background-color','#FFFFFF');
                $(\".labelcaptcha\").css('display','none');
                $(\".labelcaptcha\").html('');
            });
            function validCaptcha() {
                valid=true;
        	    if(!$(\"#captcha\").val()) {
                    $(\"#captcha\").css('background-color','#FFBDBD');
                    $(\".labelcaptcha\").css('display','block');
                    $(\".labelcaptcha\").html('You most type the captcha');
        		    valid = false;
            	}
            	return valid;
            }
            function refreshCaptcha() {
                $(\"#captcha_code\").attr('src','".$this->url."');
            }
        </script>";
    }
    function __construct(){
        $this->url='http://'.$_SERVER['HTTP_HOST'].str_replace($_SERVER['DOCUMENT_ROOT'], '', __FILE__);
        if($_SERVER['HTTPS']){
            $this->url='https://'.$_SERVER['HTTP_HOST'].str_replace($_SERVER['DOCUMENT_ROOT'], '', __FILE__);
        }
        if (isset($_GET['getHtml'])){
            echo $this->setHtml();
        } else $this->Captcha();
    }
}
$captcha = new captcha();
?>
Coloca el tag <captcha></captcha> en el archivo html donde quieras que aparezca el capcha.
Coloca este código javascript al final del archivo html para cargar el captcha
(function(){
        $.ajax({url:"<path al codigo php>?getHtml=1", success: function(result){
        $("captcha").html(result);
      }});
    })();



Comentarios sobre la versión: 1 (2)

Imágen de perfil
26 de Abril del 2021
estrellaestrellaestrellaestrellaestrella
Muy bueno!!! felicidades!!!

Cabe decir que necesita JQuery
Responder
Mario Hechavarria
26 de Abril del 2021
estrellaestrellaestrellaestrellaestrella
Hola Joel.
Gracias por tu valoración y ciertamente tienes mucha razón, es necesario incluir JQuery en el código html.
Gracias
Responder

Comentar la versión: 1

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s7023