Tweet, Share & Like [ EnAcCiOn ]

 

FeedBurner FeedCount Y Facebook | EnAcCiOn

Send Voicemail | EnAcCiOn

Contact me using vCita | EnAcCiOn

Contact me using vCita | EnAcCiOn

Meeting Scheduler Powered by vCita

martes, 16 de junio de 2015

Verification "g-recaptcha-response" PHP doesn't work

Hi there,I've tried some solutions, proposed in different blogs. None of them works, the form can still be sent without filling the reCaptcha-checkbox. The support of the earlier version 1.0 seemed to be more explained. OK, it's very easy to display the new one in a website, but what good is that if validation is so difficult. I'm not a programmer but a webdesigner.I would love it someone could help me with a hint about my error or something else that really works with my process_form.php. The lines in red I found on Youtube, don't wor, maybe the reson is, they are wrong implemented.field_rules = array(    'field1'=>'required',    'field2'=>'required',    'field6'=>'email|required',    'field7'=>'required');$form->validate();class ProcessForm{    public $field_rules;    public $error_messages;    public $fields;    private $error_list;    private $is_xhr;    function __construct()    {        $this->error_messages = array(            'required' => 'Bitte füllen Sie dieses Feld aus',            'email' => 'Bitte geben Sie eine gültige E-Mail-Adresse an',            'number' => 'Bitte geben Sie einen numerischen Wert ein',            'url' => 'Bitte geben Sie eine gültige URL ein',            'pattern' => 'Bitte korrigieren Sie diesen Wert',            'min' => 'Bitte geben Sie einen größeren Wert als das Minimum ein',            'max' => 'Bitte geben Sie einen kleineren Wert als das Maximum ein'        );                $this->field_rules = array();        $this->error_list = '';        $this->fields = $_POST;        $this->is_xhr = $this->xhr();    }    function validate()    {        if (!empty($this->fields))        {            //Validate each of the fields            foreach ($this->field_rules as $field => $rules)            {                $rules = explode('|', $rules);                foreach ($rules as $rule)                {                    $result = null;                    if (isset($this->fields[$field]))                    {                        $param = false;                        if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match))                        {                            $rule = $match[1];                            $param = $match[2];                        }                        $this->fields[$field] = $this->clean($this->fields[$field]);                        //if the field is a checkbox group create string                        if (is_array($this->fields[$field]))                            $this->fields[$field] = implode(', ', $this->fields[$field]);                        // Call the function that corresponds to the rule                        if (!empty($rule))                            $result = $this->$rule($this->fields[$field], $param);                                                        //reCaptcha                            if(isset($_POST['g-recaptcha-response'])&& $_POST['g-recaptcha-response']){  var_dump($_POST);  $secret = "my-secret-key";  $ip = $_SERVER['REMOTE_ADDR'];  $captcha = $_POST['g-recaptcha-response'];  $rsp  = file_get_contents("http://bit.ly/1GJIZSX");  var_dump($rsp);  $arr = json_decode($rsp,TRUE);   if($arr['success']){ echo 'Done'; }  else{   echo 'SPam';  } }                        // Handle errors                        if ($result === false)                            $this->set_error($field, $rule);                    }                }            }                                    if (empty($this->error_list))            {                if ($this->is_xhr)                    echo json_encode(array('status' => 'success'));                $this->process();            }            else            {                if ($this->is_xhr)                    echo json_encode(array('status' => 'invalid', 'errors' => $this->error_list));                else echo $this->error_list;            }        }    }    function process()    {         /**         * SUCCESS!!         * There were no errors in the form. Insert your processing logic here (i.e. send an email, save to a         * database etc.         *         * All of the submitted fields are available in the $this->fields variable.         *         *         * IMPORTANT - PLEASE READ:         * 1. YOU MUST UNCOMMENT THE CODE FOR IT TO WORK.         *    - This means removing the '//' in front of each line.         *    - If you do not know what php comments are see here: http://bit.ly/1cY6gCF *         * 2. YOU CAN ENTER ANY EMAIL ADDRESS IN THE $from VARIABLE.         *    - This is the address that will show in the From column in your mail application.         *    - If your form contains an email field, and you want to use that value as the $from variable, you can set $from = $this->fields['name of your email field'];         *         * 3. FILE ATTACHMENTS         *    - As stated in the description on codecanyon, this code does not mail attachments. Google 'php html email attachments' for information on how to do this         *         *  4. REDIRECTING TO ANOTHER PAGE AFTER SUBMISSION         *    - This is an ajax enabled form, so you need to perform the redirection in main.js AND this php file.         *      a. Please see instructions in main.js for redirection. This is for users without JS.         *      b. Replace the relevant code below with the page you would like to redirect to. REMEMBER TO UNCOMMENT THE LINE FOR IT TO WORK.         */         /*********************************************/         /*             SAMPLE MAIL CODE              */         /*********************************************/        $msg = "Neue Nachricht aus dem Kontaktformular: \n\n";        foreach($this->fields as $key => $field)             $msg .= "$key :  $field \n\n";         $to = 'example@domain.de';         $subject = 'Nachricht für XXX';         $from = $this->fields['E-Mail'];         mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");        /************************************************************************************/        /*                                REDIRECTION CODE                                  */        /*         Only uncomment the line below if you want to redirect to another page    */        /*                          when the form has been submitted                        */        /************************************************************************************/    if (!$this->is_xhr)    header('Location: http://examle.com');    }    function set_error($field, $rule)    {        if ($this->is_xhr)        {            $this->error_list[$field] = $this->error_messages[$rule];        }        else $this->error_list .= "
$field: " . $this->error_messages[$rule] . "
";    }    function xhr()    {        return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false;    }    /** Validation Functions */    function required($str, $val = false)    {        if (!is_array($str))        {            $str = trim($str);            return ($str == '') ? false : true;        }        else        {            return (!empty($str));        }    }    function email($str)    {        return (!preg_match("/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD", $str)) ? false : true;    }    function number($str)    {        return (!is_numeric($str)) ? false : true;    }    function min($str, $val)    {        return ($str >= $val) ? true : false;    }    function max($str, $val)    {        return ($str <= $val) ? true : false;    }    function pattern($str, $pattern)    {        return (!preg_match($pattern, $str)) ? false : true;    }    function clean($str)    {        $str = is_array($str) ? array_map(array("ProcessForm", 'clean'), $str) : str_replace('\\', '\\\\', strip_tags(trim(htmlspecialchars((get_magic_quotes_gpc() ? stripslashes($str) : $str), ENT_QUOTES))));        return $str;    }}    ?> -- You received this message because you are subscribed to the Google Groups "reCAPTCHA" group. To unsubscribe from this group and stop receiving emails from it, send an email to recaptcha+unsubscribe@googlegroups.com. To post to this group, send email to recaptcha@googlegroups.com. Visit this group at http://bit.ly/1dkFnYd. For more options, visit http://bit.ly/P65DvS.

No hay comentarios:

EnAcCiOn

Contador Web | EnAcCiOn

EnAcCiOn

EnAcCiOn

EnAcCiOn

Blog Archive | EnAcCiOn