本文整理汇总了PHP中Handler::validate_input方法的典型用法代码示例。如果您正苦于以下问题:PHP Handler::validate_input方法的具体用法?PHP Handler::validate_input怎么用?PHP Handler::validate_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Handler
的用法示例。
在下文中一共展示了Handler::validate_input方法的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));
}