当前位置: 首页>>代码示例>>PHP>>正文


PHP HTTP::response方法代码示例

本文整理汇总了PHP中HTTP::response方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP::response方法的具体用法?PHP HTTP::response怎么用?PHP HTTP::response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTTP的用法示例。


在下文中一共展示了HTTP::response方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: authenticate

 private function authenticate($params)
 {
     //check if all the params are supplied
     $valid_params = isset($params->UUID) && isset($params->MAC);
     if (!$valid_params) {
         return HTTP::response('400');
     }
     //validate the user
     $sql = "SELECT id\n                FROM presence_users pu\n                WHERE pu.UUID = ? AND pu.mac = ?";
     $user = DB::getRecord($sql, array(sha1($params->UUID), sha1($params->MAC)));
     //check if we obtained a numeric id
     if (!$user || !is_int((int) $user->id)) {
         return HTTP::response('401');
     }
     //check if the user does not have a token already
     $old_token = $this->get_token($user->id);
     if ($old_token) {
         API::response($old_token);
     }
     //generate the token
     $auth = new stdClass();
     $auth->userid = $user->id;
     $auth->token = sha1(time() * rand());
     $auth->timeexpires = time() + 24 * 60 * 60;
     $auth_response = DB::putRecord('presence_auth', $auth);
     if ($auth_response) {
         unset($auth->userid);
         API::response($auth);
     }
 }
开发者ID:robertboloc,项目名称:presence-manager,代码行数:30,代码来源:User.php

示例2: validate_token

 private function validate_token($token)
 {
     $sql = "SELECT id\n                FROM presence_auth pa\n                WHERE pa.token = ?\n                AND pa.timeexpires > ?";
     $response = DB::getRecord($sql, array($token, time()));
     if (!$response) {
         HTTP::response('401');
     }
     //set the request token
     $this->_token = $token;
 }
开发者ID:robertboloc,项目名称:presence-manager,代码行数:10,代码来源:API.php

示例3: unlock

 /**
  * Release a lock
  */
 public function unlock()
 {
     $key = filter_input(INPUT_GET, 'key');
     if (empty($key)) {
         throw new Exception("No key argument specified");
     }
     list($key, $check) = explode(':', $key, 2) + array(1 => null);
     $lock = 'nbd-cms.lock.' . $key;
     $info = apc_fetch($lock);
     if (empty($info)) {
         HTTP::response(204);
         echo "Lock does not exist";
         exit;
     }
     if ($info['check'] != $check) {
         HTTP::response(423);
         //locked
         echo "Invalid token: You do not own that lock.";
         exit;
     }
     apc_delete($lock);
     echo 1;
 }
开发者ID:jasny,项目名称:Q,代码行数:26,代码来源:CRUD.php

示例4: isset

});
// create the DB connection
DB::setUp($CONFIG);
// validate and respond to the request
$method = $_SERVER['REQUEST_METHOD'];
$url = isset($_GET['url']) ? $_GET['url'] : null;
switch ($method) {
    case 'GET':
        $params = (object) $_GET;
        break;
    case 'POST':
        $params = (object) $_POST;
        break;
    default:
        HTTP::response('405');
        //Method Not Allowed
}
$url_fragments = explode('/', trim($url, '/'));
if (count($url_fragments) != 3) {
    HTTP::response('400');
    //Bad Request
}
//format of the response
$format = $url_fragments[0];
//resource
$resource = $url_fragments[1];
//action to be made on the resource
$action = $url_fragments[2];
//check if the required format is implemented and if the resource exists
is_dir(ROOT . '/api/' . $format) && class_exists(ucfirst($resource)) ? new $resource($action, $params) : HTTP::response('400');
//Bad Request
开发者ID:robertboloc,项目名称:presence-manager,代码行数:31,代码来源:index.php


注:本文中的HTTP::response方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。