我在Laravel5.1上有一个单页的应用程序。我使用localStorage来保存API密钥,并且不需要cookie。拉勒维尔为我做了两个饼干:
XSRF-令牌
laravel_session
如果我在环境配置中将SESSION_DRIVER设置为array,则不再生成laravel_session cookie。
但是我认为XSRF-TOKEN cookie可能有问题,因为我在VerifyCsrfToken中间件类中发现了这段代码:
public function handle($request, Closure $next)
{
if ($this->isR
我在EncryptCookies中为api启用了kernel.php
在我的中间件/Authenticate.php文件中,我无法访问cookie。他们被加密了。
Authenticate.php:
protected function authenticate($request, $guards)
{
$token = $request->cookie('something'); // Now it stores the encryted cookie
}
顺便说一句,我可以把它们用在我的控制器上。我怎样才能在中间件中使用它们?
我用Laravel 5创建了一个网站,为了跟踪其他网站引用的用户,我使用了以下中间件,它通过请求参数识别引用并设置cookie。
<?php
namespace App\Http\Middleware;
use Closure;
class AffiliateTrackingMiddleware {
public static $trackingCookieName = "refId";
public static $trackingURLParameter = "refId";
/**
* Handle an
我正在使用Laravel5.1,我正在尝试实现一个基本的JWT-Auth逻辑。
当我创建jwt_token时(我将它记录到laravel.log,令牌有三个不同的部分按预期的点除以),当我尝试创建一个带有jwt_token值的cookie时,就会创建一个完全不同的cookie,没有按点除法,它比原来的jwt_token要大得多。
我认为代码非常简单:
$jwt_token = $this->findOrCreateUser($user);
Log::error('My jwt_token is '. $jwt_token); //from the log here i s
我的项目中有一个中间件,可以调用每个请求。它将检查请求是否具有特定cookie,然后删除另一个cookie。但似乎在响应返回之前,Cookie并没有被遗忘或设置在Laravel中。像return response('view')->withCookie($cookie);这样的东西在中间件中是不可能的。 我也尝试了Cookie::queue(Cookie::forget('myCookie'));,没有发生任何事情,cookie显示在我的浏览器中。 这是我的中间件句柄方法: public function handle(Request $request,
我通过Javascript设置了一个cookie my_cookie
function createCookie(name, value, days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toUTCString();
}
else {
expi
我得到了以下序列化提供程序:
class CartServiceProvider extends ServiceProvider {
public function boot() {
}
public function register() {
$this->app->singleton(\Alexxosipov\Cart\Cart::class, function($app) {
return new \Alexxosipov\Cart\Cart($app['request']);
你好,我需要解密cookie的值。我要创建和销毁的代码:
public function setSession($id){
Cookie::queue('userId', $id, 10000);
}
public function destroySession(){
Cookie::queue(Cookie::forget('userId'));
}
但是我需要在不加密的情况下获取cookie的值。
我在从5.2升级Laravel 5.3的时候遇到了问题。
发生以下错误
ReflectionException: Class does not exist in /MYPROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php:749
[2018-05-08 07:14:18] production.ERROR: ReflectionException: Class does not exist in /opt/lampp/htdocs/MYPROJ/vendor/laravel/framework/sr
我创建了一个中间件,如下所示:
use Closure;
use Gate;
class ACLMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Gate::den
我在排除验证CSRF令牌的路径方面有问题。
我试图排除端点上的所有请求,我称之为mydomain.com/示例,因此我喜欢在VerifyCsrfToken.php文件中这样做。
class VerifyCsrfToken extends Middleware
{
/**
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
*
* @var bool
*/
protected $addHttpCookie = true;
/**
我想添加一个http响应头到我的应用程序的所有响应。我刚刚创建了一个新的中间件,如下所示:
namespace Ibbr\Http\Middleware;
use Closure;
class XFrameOptionsHeader
{
public function handle($request, Closure $next)
{
$response = $next($request);
$response->header('X-Frame-Options', 'deny');
r