本文整理匯總了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));
}