Прошу помощи в добавление капчи к php форме

Тема в разделе "PHP", создана пользователем boxerrr, 27 май 2014.

  1. boxerrr

    boxerrr

    Регистрация:
    8 авг 2013
    Сообщения:
    105
    Симпатии:
    36
    Есть форма php к ней нужно прикрутить капчу я если честно полный юзер в этом но сделать надо поэтому прошу помощи!!!
    Вот сама форма
    PHP:
    <?php
        
    /**
         * ВНИМАНИЕ
         * Для работы с API на сервере должны быть установлены расширения Curl и JSON
         */
    $connect = array(
        
    'ip' => '',      //IP адрес Вашего сервера Такси-Мастер
        
    'port' => '',             //Порт, который указан в настройках ТМ API
        
    'secret' => '',      //Cекретный ключ, который указан в настройках ТМ API
        
    'method' => 'create_order'
    );

    function 
    serviceIsAvailable$connect ) {
        
    $requestArgs getArgs();
        
    $ch curl_init"https://".$connect['ip'].":".$connect['port']."/common_api/1.0/get_tariffs_list?" $requestArgs );
        
    curl_setopt$chCURLOPT_RETURNTRANSFERTRUE );
        
    curl_setopt$chCURLOPT_SSL_VERIFYPEERfalse );
        
    curl_setopt$chCURLOPT_SSL_VERIFYHOSTfalse );
        
    curl_setopt$chCURLOPT_TIMEOUT);
        
    curl_setopt$chCURLOPT_HTTPHEADER, array(
            
    'Signature: ' md5$requestArgs $connect['secret'] ),
            
    'Content-Type: application/x-www-form-urlencode'
        
    ));

        
    $response json_decode(curl_exec$ch ));
        
    $error_code curl_errno($ch);
        
    curl_close($ch);
        return ( 
    $response->code == ) && ( !empty($response->data->tariffs) ) && ( $error_code == 0);
    }

    function 
    getArgs$extra = array() ) {
        return 
    http_build_query(array_merge(
                array(
                    
    'pay_system_type'   => '0',
                    
    'account'           => '123400542',//'004700-000003',
                    
    'oper_id'           => '20120813182430',//'20120813182430',
                    
    'sum'               => '1',
                    
    'oper_time'         => '20120813182430',
                    
    'test'              => '1'
                
    )
                , 
    $extra)
        );
    }

    function 
    addOperation$connect$phone$address$customer$comment ) {
        
    $requestArgs getArgs(array( 'phone' => $phone'source' => $address'source_time' => date('YmdHis'), 'customer' => $customer'comment' => $comment ));
        
    $ch curl_init"https://".$connect['ip'].":".$connect['port']."/common_api/1.0/".$connect['method'] );

        
    curl_setopt$chCURLOPT_POSTTRUE );
        
    curl_setopt$chCURLOPT_POSTFIELDS$requestArgs );
        
    curl_setopt$chCURLOPT_RETURNTRANSFERTRUE );
        
    curl_setopt$chCURLOPT_SSL_VERIFYPEERfalse );
        
    curl_setopt$chCURLOPT_SSL_VERIFYHOSTfalse );
        
    curl_setopt$chCURLOPT_TIMEOUT);
        
    curl_setopt$chCURLOPT_HTTPHEADER, array(
            
    'Signature: ' md5$requestArgs $connect['secret'] ),
            
    'Content-Type: application/x-www-form-urlencode'
        
    ));

        
    $response json_decode(curl_exec$ch ));
        
    $error_code curl_errno($ch);
        
    curl_close($ch);
        if( 
    $response->code == && !empty($response->data->order_id) && ( $error_code == 0) ) {
            return 
    true;
        } else {
            return 
    $response->descr;
        }
    }

    $result = array();
    $errorMessage = array();
    if( !
    function_exists('curl_init') ) {
        
    $errorMessage[] = 'не установлен curl';
    }
    if ( !
    function_exists('json_encode') ) {
        
    $errorMessage[] = 'не установлен json';
    }
    if( empty( 
    $_POST['Number'] ) || empty( $_POST['OrderSourceAddress'] ) ) {
        
    $errorMessage[] = 'не указан обязательный параметр.';
    }
    if( 
    serviceIsAvailable$connect ) ) {
        
    $subResult addOperation$connect$_POST['Number'], $_POST['OrderSourceAddress'], $_POST['OrderClientName'], $_POST['OrderComment'] );
        if( 
    $subResult === true ) {
            
    $result 'Заказ успешно принят.';
        } else {
            
    $errorMessage[] = $subResult;
        }
    } else {
        
    $errorMessage[] = 'Сервис недоступен. Проверьте настройки подключения.';
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <html>
    <head>
        <title>Такси</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <style type="text/css">
            body {
                font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
                font-size: 13px;
                line-height: 18px;
                color: #333;
            }
            p {
                margin: 0 0 9px;
            }
            input, button, select, textarea {
                font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
            }
            input, textarea, .uneditable-input {
                margin-left: 0;
            }
            select, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input {
                display: inline-block;
                height: 18px;
                padding: 4px;
                margin-bottom: 9px;
                font-size: 13px;
                line-height: 18px;
                color: #555;
            }
            textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input {
                background-color: white;
                border: 1px solid #CCC;
                -webkit-border-radius: 3px;
                -moz-border-radius: 3px;
                border-radius: 3px;
                -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
                -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
                box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
                -webkit-transition: border linear .2s,box-shadow linear .2s;
                -moz-transition: border linear .2s,box-shadow linear .2s;
                -ms-transition: border linear .2s,box-shadow linear .2s;
                -o-transition: border linear .2s,box-shadow linear .2s;
                transition: border linear .2s,box-shadow linear .2s;
            }
            textarea:focus, input[type="text"]:focus, input[type="password"]:focus, input[type="datetime"]:focus, input[type="datetime-local"]:focus, input[type="date"]:focus, input[type="month"]:focus, input[type="time"]:focus, input[type="week"]:focus, input[type="number"]:focus, input[type="email"]:focus, input[type="url"]:focus, input[type="search"]:focus, input[type="tel"]:focus, input[type="color"]:focus, .uneditable-input:focus {
                border-color: rgba(82, 168, 236, 0.8);
                outline: 0;
                -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075),0 0 8px rgba(82, 168, 236, 0.6);
                -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);
                box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075),0 0 8px rgba(82, 168, 236, 0.6);
            }
            input, textarea {
                width: 210px;
            }
            textarea {
                height: auto;
            }
            input[type="submit"], input[type="reset"], input[type="button"], input[type="radio"], input[type="checkbox"] {
                width: auto;
            }
            .btn {
                display: inline-block;
                padding: 4px 10px 4px;
                margin-bottom: 0;
                font-size: 13px;
                line-height: 18px;
                color: #333;
                text-align: center;
                text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
                vertical-align: middle;
                cursor: pointer;
                background-color: whiteSmoke;
                background-image: -ms-linear-gradient(top,white,#E6E6E6);
                background-image: -webkit-gradient(linear,0 0,0 100%,from(white),to(#E6E6E6));
                background-image: -webkit-linear-gradient(top,white,#E6E6E6);
                background-image: -o-linear-gradient(top,white,#E6E6E6);
                background-image: linear-gradient(top,white,#E6E6E6);
                background-image: -moz-linear-gradient(top,white,#E6E6E6);
                background-repeat: repeat-x;
                border: 1px solid #CCC;
                border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
                border-bottom-color: #B3B3B3;
                -webkit-border-radius: 4px;
                -moz-border-radius: 4px;
                border-radius: 4px;
                filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffffff',endColorstr='#e6e6e6',GradientType=0);
                filter: progid:dximagetransform.microsoft.gradient(enabled=false);
                -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2),0 1px 2px rgba(0, 0, 0, 0.05);
                -moz-box-shadow: inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05);
                box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2),0 1px 2px rgba(0, 0, 0, 0.05);
            }
            .btn.active, .btn:active {
                background-color: #E6E6E6;
                background-image: none;
                outline: 0;
                -webkit-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15),0 1px 2px rgba(0, 0, 0, 0.05);
                -moz-box-shadow: inset 0 2px 4px rgba(0,0,0,0.15),0 1px 2px rgba(0,0,0,0.05);
                box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15),0 1px 2px rgba(0, 0, 0, 0.05);
            }
            .btn-primary, .btn-primary:hover {
                color: white;
                text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
                background-image: none;
            }
            .btn-primary{
                background-color: #05C;
            }
            .btn-primary:hover, .btn-primary:active {
                background-color: #05C;
            }
            .btn-primary:active, .btn-primary.active {
                background-color: #004099;
            }
            label {
                display: block;
                margin-bottom: 5px;
            }
            label, input, button, select, textarea {
                font-size: 13px;
                font-weight: normal;
                line-height: 18px;
            }
            .alert {
                padding: 8px 35px 8px 14px;
                margin-bottom: 18px;
                color: #C09853;
                text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
                background-color: #FCF8E3;
                border: 1px solid #FBEED5;
                -webkit-border-radius: 4px;
                -moz-border-radius: 4px;
                border-radius: 4px;
            }
            .alert-danger, .alert-error {
                color: #B94A48;
                background-color: #F2DEDE;
                border-color: #EED3D7;
            }
            .alert-info {
                color: #3A87AD;
                background-color: #D9EDF7;
                border-color: #BCE8F1;
            }
            .alert-success {
                color: #468847;
                background-color: #DFF0D8;
                border-color: #D6E9C6;
            }
            h2{
                margin-bottom: 10px;
            }
            .booking-wrapper{
                padding: 20px 20px 0 20px;
            }
            tr > td{
                vertical-align: top;
            }
            .settings-wrapper{
                height: 40px;
                padding: 10px 0 0 20px;
            }
            .settings label, .settings input{
                display: block;
                float: left;
            }
            .settings label{
                margin-right: 5px;
                padding: 3px;
            }
            .settings input{
                margin-right: 5px;
            }
        </style>
    </head>
    <body>

    <div class="booking-wrapper">
        <?php if( !empty($_POST) ) { ?>
            <?php if( empty($errorMessage) ) { ?>
                    <p class="alert alert-success"><?php echo $result?></p>
                <?php } else { ?>
                    <p class="alert alert-info"><?php echo implode(' '$errorMessage); ?></p>
                <?php ?>
            <?php } else { ?>
    <!--        <p class="alert alert-info">Выберите параметры</p>-->
        <?php ?>

        <form action="" method="post">
            <h2>Создание заказа</h2>
            <table>
                <tr>
                    <td width="175" align="right" valign="middle" class="bold">
                        *Номер телефона:
                    </td>
                    <td>
                        <input type="text" name="Number" class="inp" maxlength="11" size="10"
                               value="<?php echo isset($_POST['Number']) ? $_POST['Number'] : '' ?>"/><br/>
                        Пример: <strong>555111</strong> или <strong>89331515153</strong>
                    </td>
                </tr>

                <tr>
                    <td width="175" align="right" valign="middle">Ваше имя и отчество:</td>
                    <td><input type="text" name="OrderClientName" class="inp" maxlength="50"
                               size="35"
                               value="<?php echo isset($_POST['OrderClientName']) ? $_POST['OrderClientName'] : '' ?>"/><br/>
                        Пример: <strong>Василий Анатольевич</strong>
                    </td>
                </tr>

                <tr>
                    <td width="175" align="right" valign="middle" class="bold">
                        *Адрес подачи:
                    </td>
                    <td>
                        <input type="text" name="OrderSourceAddress" class="inp"
                               maxlength="50" size="35"
                               value="<?php echo isset($_POST['OrderSourceAddress']) ? $_POST['OrderSourceAddress'] : '' ?>"/><br/>
                        Пример: <strong>Пушкинская 155</strong>
                    </td>
                </tr>

                <tr>
                    <td width="175" align="right" valign="middle">Примечание:</td>
                    <td>
                        <textarea name="OrderComment" class="inp" maxlength="100" cols="35"></textarea><br/>
                        Заполнять не обязательно
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <strong>* - Поля, обязательные к заполнению.</strong>
                    </td>
                </tr>
                <tr>
                    <td> </td>
                    <td>
                        <input type="submit" name="submit" class="btn btn-primary" value="Заказать" style="float:right"/>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    </body>
    </html>
     
    Lasted edited by : 27 май 2014
  2. $iD

    $iD Команда форума

    Регистрация:
    13 мар 2012
    Сообщения:
    3.580
    Симпатии:
    1.482
    так в чём проблема? что вы пробовали ставить?
    какую, вообще, капчу хотите? их много...
    рекапча, кейкапча др.

    на рекапчах и кейкапчах есть примеры. :Smile:
     
  3. boxerrr

    boxerrr

    Регистрация:
    8 авг 2013
    Сообщения:
    105
    Симпатии:
    36
    По большему счету все равно просто поставить хоть какую нибудь защиту от ботов!!!
     
  4. дмитрий111113

    дмитрий111113

    Регистрация:
    18 мар 2014
    Сообщения:
    39
    Симпатии:
    12
    https://www.google.com/recaptcha/intro/index.html Настраивается за 10 минут. надёжная в обращении, умеренная по замороченности текста для ввода.
     
  5. ironic

    ironic

    Регистрация:
    10 дек 2013
    Сообщения:
    16
    Симпатии:
    3
    Имхо самое просто по защите от ботов это записать куку ))

    <?php
    //вначале формы генерим секретный ключ
    $nobotkey = date("j") * (date("w")+2);
    ?>

    Потом пишем его в куку явой:
    <script language="JavaScript">
    function setCookie(cookieName, cookieValue, expires, path, domain, secure) {
    document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; EXPIRES=' + expires.toGMTString() : '') + (path ? '; PATH=' + path : '') + (domain ? '; DOMAIN=' + domain : '') + (secure ? '; SECURE' : '');
    }
    setCookie("nobotkey", "<?php echo $nobotkey; ?>");
    </script>

    В обработчике формы проверям куку:
    <?php
    if (empty($_COOKIE['nobotkey'])||($_COOKIE['nobotkeyt']!=$nobotkey)){
    $errors[] = 'Pls, <b>enable cookies and JavaScript</b> in you browser!';
    }
    ?>

    Ву-а-ля...