當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Handler::verify_bot_searched方法代碼示例

本文整理匯總了PHP中Handler::verify_bot_searched方法的典型用法代碼示例。如果您正苦於以下問題:PHP Handler::verify_bot_searched方法的具體用法?PHP Handler::verify_bot_searched怎麽用?PHP Handler::verify_bot_searched使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Handler的用法示例。


在下文中一共展示了Handler::verify_bot_searched方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: header

<?php

header('Access-Control-Allow-Origin: http://ajaxlivesearch.com');
header('Access-Control-Allow-Methods: *');
header('Content-Type: application/json');
header_remove('X-Powered-By');
file_exists(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'handler.php')) ? require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'handler.php') : die('There is no such a file: handler.php');
// 1. Validate all inputs
$errors = Handler::validate_input($_POST);
if (count($errors) === 0) {
    // 2. A layer of security against those Bots that submit a form quickly
    if (Handler::verify_bot_searched($_POST['ls_page_loaded_at'])) {
        // 3. Verify the token - CSRF protection
        if (Handler::verify_session_value('token', $_POST['ls_token']) && Handler::verify_session_value('anti_bot', $_POST['ls_anti_bot'])) {
            // 4. Start looking for the query
            $result = json_encode(Handler::get_result($_POST['ls_query'], (int) $_POST['ls_current_page'], (int) $_POST['ls_items_per_page']));
            // 5. Return the result
            Handler::form_response('success', 'Successful request', $result);
        } else {
            // Tokens are not matched
            Handler::form_response('failed', 'Error: Please refresh the page. It seems that your session is expired.');
        }
    } else {
        // Searching is started sooner than the search start time offset
        Handler::form_response('failed', 'Error: You are too fast, or this is a Bot. Please search now.');
    }
} else {
    // Required inputs are not provided
    Handler::form_response('failed', "Error: Required or invalid inputs: " . implode(',', $errors));
}
開發者ID:vestar7,項目名稱:ajax-live-search,代碼行數:30,代碼來源:process_livesearch.php


注:本文中的Handler::verify_bot_searched方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。