本文整理匯總了PHP中Illuminate\Support\Facades\Request::header方法的典型用法代碼示例。如果您正苦於以下問題:PHP Request::header方法的具體用法?PHP Request::header怎麽用?PHP Request::header使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Facades\Request
的用法示例。
在下文中一共展示了Request::header方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getInterfaceLocale
public function getInterfaceLocale()
{
$locale = Input::get("l");
$translating = Input::get("t");
$primary = Input::get("p");
$displayLocales = Input::get("d");
$display = implode(',', $displayLocales ?: []);
App::setLocale($locale);
Cookie::queue($this->cookieName(self::COOKIE_LANG_LOCALE), $locale, 60 * 24 * 365 * 1);
Cookie::queue($this->cookieName(self::COOKIE_TRANS_LOCALE), $translating, 60 * 24 * 365 * 1);
Cookie::queue($this->cookieName(self::COOKIE_PRIM_LOCALE), $primary, 60 * 24 * 365 * 1);
Cookie::queue($this->cookieName(self::COOKIE_DISP_LOCALES), $display, 60 * 24 * 365 * 1);
if (App::runningUnitTests()) {
return Redirect::to('/');
}
return !is_null(Request::header('referer')) ? Redirect::back() : Redirect::to('/');
}
示例2: redirectBackWithFallback
/**
* Redirect back, with a fallback if no previous page.
*
* @param string $fallback
*
* @return \Illuminate\Http\RedirectResponse
*/
protected function redirectBackWithFallback($fallback = '/')
{
if (!Request::header('referer')) {
return Redirect::to($fallback);
}
return Redirect::back();
}
示例3: users
public function users()
{
$auth_token = Request::header('Authorization');
$user = User::where('auth_token', '=', $auth_token)->first();
if ($user) {
$users = User::getActiveUsersInfo()->get();
foreach ($users as $u) {
$user_element["id"] = $u->id;
$user_element["names"] = $u->nombres;
$user_element["last_name"] = $u->apellido_pat;
$user_element["username"] = $u->num_documento;
$perfiles = User::getPerfilesPorUsuario2($u->id)->get();
$perfiles_array = array();
foreach ($perfiles as $perfil) {
$perfiles_array[] = ['id' => $perfil->idperfiles, 'name' => $perfil->nombre];
}
$user_element["profiles"] = $perfiles_array;
$permisos = User::getPermisosPorUsuarioId($u->id)->get();
$permisos_array = array();
foreach ($permisos as $p) {
$permisos_array[] = ['id' => $p->idpermisos];
}
$user_element["actions"] = $permisos_array;
$user_element["auth_token"] = $u->auth_token;
$user_array[] = $user_element;
}
return Response::json($user_array, 200);
}
$response = ['error' => 'Error en la autenticación.'];
$status_code = 401;
return Response::json($response, $status_code);
}
示例4: login
public function login()
{
$apps_key = Request::header('Application-Key');
$auth_key = Request::header('Authorization');
if (System::where('api_token', $apps_key)->get()->count() < 1) {
return Response::json(['status' => 400, 'message' => http_codes(400)], 400);
}
if (!($credentials = array_filter(explode(" ", $auth_key)))) {
return Response::json(['error' => 'invalid_credentials'], 401);
}
if (!($auth = array_filter(explode(":", base64_decode($credentials[1]))))) {
return Response::json(['error' => 'invalid_credentials'], 401);
}
if (!Auth::attempt(['name' => $auth[0], 'password' => $auth[1]])) {
return Response::json(['status' => 401, 'message' => http_codes(401)], 401);
}
try {
$data = ['userId' => Auth::user()->id];
if (!($token = JWT::setToken($data))) {
return Response::json(['error' => 'invalid_credentials'], 401);
}
} catch (Exception $e) {
return Response::json(['error' => 'could_not_create_token'], 500);
}
return Response::json(['status' => 200, 'message' => http_codes(200), 'data' => $token], 200);
}
示例5: getExceptionData
private function getExceptionData($exception)
{
$data = [];
$data['host'] = Request::server('HTTP_HOST');
$data['method'] = Request::method();
$data['fullUrl'] = Request::fullUrl();
if (php_sapi_name() === 'cli') {
$data['host'] = parse_url(config('app.url'), PHP_URL_HOST);
$data['method'] = 'CLI';
}
$data['exception'] = $exception->getMessage();
$data['error'] = $exception->getTraceAsString();
$data['line'] = $exception->getLine();
$data['file'] = $exception->getFile();
$data['class'] = get_class($exception);
$data['storage'] = array('SERVER' => Request::server(), 'GET' => Request::query(), 'POST' => $_POST, 'FILE' => Request::file(), 'OLD' => Request::hasSession() ? Request::old() : [], 'COOKIE' => Request::cookie(), 'SESSION' => Request::hasSession() ? Session::all() : [], 'HEADERS' => Request::header());
$data['storage'] = array_filter($data['storage']);
$count = $this->config['count'];
$data['exegutor'] = [];
$data['file_lines'] = [];
$file = new SplFileObject($data['file']);
for ($i = -1 * abs($count); $i <= abs($count); $i++) {
list($line, $exegutorLine) = $this->getLineInfo($file, $data['line'], $i);
$data['exegutor'][] = $exegutorLine;
$data['file_lines'][$data['line'] + $i] = $line;
}
// to make Symfony exception more readable
if ($data['class'] == 'Symfony\\Component\\Debug\\Exception\\FatalErrorException') {
preg_match("~^(.+)' in ~", $data['exception'], $matches);
if (isset($matches[1])) {
$data['exception'] = $matches[1];
}
}
return $data;
}
示例6: facebookLogin
public function facebookLogin(Request $request)
{
//get fb access token
// verify fb access token
// generate token for user
// update token in db
// return token for user
// else return false
$user_ac_token = \Illuminate\Support\Facades\Request::header('fbtoken');
//facebook access token
$userEmail = $request->json()->get('email');
$info = json_decode(file_get_contents('https://graph.facebook.com/app/?access_token=' . $user_ac_token), true);
if ($info['id'] == env('FB_APP_ID')) {
$user = User::with('school')->where('email', '=', $userEmail)->first();
if ($user != null) {
//login
$user->auth_token = str_random(60);
$user->save();
return Response::json(['result' => 'success', 'token' => $user->auth_token, 'user' => $user], 200);
} else {
$user = User::with('school')->find(User::create($request->all())->id);
$user->auth_token = str_random(60);
$user->save();
return Response::json(['result' => 'success', 'token' => $user->auth_token, 'user' => $user], 200);
}
} else {
return Response::json(['result' => 'failed'], 400);
}
}
示例7: push_settings
public function push_settings()
{
$auth_token = Request::header('Authorization');
$user = User::where('auth_token', '=', $auth_token)->first();
if ($user) {
$data = file_get_contents('php://input');
$settingsInput = (array) json_decode($data);
if ($settingsInput) {
$user->push_eventos = $settingsInput['push_events'];
$user->push_pagos = $settingsInput['push_fees'];
$user->push_documents = $settingsInput['push_documents'];
$user->push_reports = $settingsInput['push_reports'];
$user->save();
$response = ['success' => 1];
$status_code = 200;
return Response::json($response, $status_code);
} else {
$response = ['error' => 'Parámetro settings inválido (vacío/formato JSON incorrecto).'];
$status_code = 400;
return Response::json($response, $status_code);
}
}
$response = ['error' => 'Error en la autenticación.'];
$status_code = 401;
return Response::json($response, $status_code);
}
示例8: handle
/**
* Write a logout history item for this user
*
* @param \Illuminate\Auth\Events\Logout $event
*/
public static function handle(LogoutEvent $event)
{
$event->user->login_history()->save(new UserLoginHistory(['source' => Request::getClientIp(), 'user_agent' => Request::header('User-Agent'), 'action' => 'logout']));
$message = 'User logged out from ' . Request::getClientIp();
event('security.log', [$message, 'authentication']);
return;
}
示例9: getResponse
/**
* Check headers to see if we should localize the content, if so, create a new response and get it to do the
* localization.
*
* @return ApiResponse
*/
public function getResponse()
{
$apiResponse = new ApiResponse();
if ($region = RequestFacade::header('Accept-Region')) {
$apiResponse->setLocalizationRegion($region);
}
return $apiResponse;
}
示例10: Logging
/**
* [Log api]
* @param [type] $url [description]
* @param [type] $method [description]
* @param [type] $request [description]
* @param [type] $response [description]
*/
public static function Logging($url, $method, $request, $response)
{
$model = new Log();
$data = $model->create(['url' => $url, 'method' => $method, 'header' => json_encode(Request::header()), 'request' => json_encode(Request::all())]);
$model = new Log();
$model = $model->findOrFail($data['id']);
$model->update(['response' => json_encode($response)]);
}
示例11: handle
/**
* Update the last login values and write a new
* login history item
*
* @param $user
*/
public static function handle($user)
{
$user->last_login_source = Request::getClientIp();
$user->last_login = new DateTime();
$user->save();
$user->login_history()->save(new UserLoginHistory(['source' => Request::getClientIp(), 'user_agent' => Request::header('User-Agent'), 'action' => 'login']));
$message = 'User logged in from ' . Request::getClientIp();
Event::fire('security.log', [$message, 'authentication']);
return;
}
示例12: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// JWT Authentication and for getting data (e.g: userId, userName, ...etc)
$jwt = Request::header('Token-Key');
try {
$data = JWT::getToken($jwt);
} catch (Exception $e) {
return Response::json(['error' => $e->getMessage()], 511);
}
$request->merge(array("data" => $data));
return $next($request);
}
示例13: handleException
/**
* Handles exceptions with redirect.
*
* @param Exception $exception
* @return Illuminate\Routing\Redirector
*/
public function handleException(Exception $exception)
{
// Get redirect
$referer = Request::header('referer');
$url = empty($referer) ? route('users.signin') : $referer;
// Add the fragment if defined on the route
$options = Request::route()->getAction();
$fragment = array_get($options, 'fragment');
$url = $fragment ? $url . '#' . $fragment : $url;
// Send redirect
return Redirect::to($url)->with('message', $exception->getMessage())->with('code', $exception->getCode())->withErrors($exception->getBag())->withInput();
}
示例14: create
public function create(array $data = null)
{
if (is_null($data)) {
return false;
}
// check null values
$arr = $this->validate($data);
// get publisher id
$uid = Request::header('UID', 0);
$arr = array_merge($arr, ['article_id' => $data['id'], 'created_by' => $uid, 'modified_by' => $uid]);
return ArticleDomainData::updateOrCreate(['article_id' => $data['id']], $arr);
}
示例15: roll_call
public function roll_call()
{
$auth_token = Request::header('Authorization');
$user = User::where('auth_token', '=', $auth_token)->first();
if ($user) {
$data = file_get_contents('php://input');
$rollCallInput = (array) json_decode($data);
if ($rollCallInput) {
try {
$sessionID = $rollCallInput['session_id'];
$volunteersInput = $rollCallInput['volunteers'];
} catch (Exception $e) {
$response = ['error' => 'Formato inválido: debe contener session_id, volunteers.'];
$status_code = 404;
return Response::json($response, $status_code);
}
foreach ($volunteersInput as $v) {
$rollCallEntry = Asistencia::validarAsistencia($v->id, $sessionID)->first();
if (!$rollCallEntry) {
$rollCallEntry = new Asistencia();
$rollCallEntry->idusers = $v->id;
$rollCallEntry->ideventos = $sessionID;
}
$rollCallEntry->asistio = $v->attended;
$rollCallEntry->calificacion = $v->rating;
$rollCallEntry->comentario = $v->comment;
$rollCallEntry->save();
}
$rollCallDB = Asistencia::getUsersPorEvento($sessionID)->get();
$responseRollCall = [];
foreach ($rollCallDB as $rollCallEntryDB) {
$responseRollCall_element['id'] = $rollCallEntryDB->id;
$responseRollCall_element['names'] = $rollCallEntryDB->nombres;
$responseRollCall_element['last_name'] = $rollCallEntryDB->apellido_pat;
$responseRollCall_element['attended'] = (bool) $rollCallEntryDB->asistio;
$responseRollCall_element['rating'] = (int) $rollCallEntryDB->calificacion;
$responseRollCall_element['comment'] = $rollCallEntryDB->comentario;
$responseRollCall[] = $responseRollCall_element;
}
$response = ['success' => 1, 'session_id' => $sessionID, 'volunteers' => $responseRollCall];
$status_code = 200;
return Response::json($response, $status_code);
} else {
$response = ['error' => 'Error en parámetros.'];
$status_code = 404;
return Response::json($response, $status_code);
}
}
$response = ['error' => 'Error en la autenticación.'];
$status_code = 401;
return Response::json($response, $status_code);
}