Laravel can't read a “recently” created cookie2019 Community Moderator ElectionCan't set PHP cookie on the same pageSet and Check Cookie in the one response - LaravelHow do I set/unset a cookie with jQuery?Create, read, and erase cookies with jQueryLocal Storage vs Cookiescookie delete problemSet cookie and get cookie with JavaScriptLaravel Setting cookies with AjaxBest Practices for Custom Helpers in Laravel 5iframe not reading cookies in ChromeMany questions about using Laravel PassportCan't get Auth object and cookies by consuming my own Laravel API
What do you call someone who likes to pick fights?
Conservation of Mass and Energy
Why restrict private health insurance?
What can I do if someone tampers with my SSH public key?
Can one live in the U.S. and not use a credit card?
What is the generally accepted pronunciation of “topoi”?
Specifying a starting column with colortbl package and xcolor
What is this diamond of every day?
Professor forcing me to attend a conference, I can't afford even with 50% funding
Source permutation
School performs periodic password audits. Is my password compromised?
What problems would a superhuman have who's skin is constantly hot?
In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?
Having the player face themselves after the mid-game
Outlet with 3 sets of wires
Getting the || sign while using Kurier
Vocabulary for giving just numbers, not a full answer
What is Tony Stark injecting into himself in Iron Man 3?
How does Ehrenfest's theorem apply to the quantum harmonic oscillator?
Why is a very small peak with larger m/z not considered to be the molecular ion?
How many characters using PHB rules does it take to be able to have access to any PHB spell at the start of an adventuring day?
Is it possible to avoid unpacking when merging Association?
Does a difference of tense count as a difference of meaning in a minimal pair?
How can I manipulate the output of Information?
Laravel can't read a “recently” created cookie
2019 Community Moderator ElectionCan't set PHP cookie on the same pageSet and Check Cookie in the one response - LaravelHow do I set/unset a cookie with jQuery?Create, read, and erase cookies with jQueryLocal Storage vs Cookiescookie delete problemSet cookie and get cookie with JavaScriptLaravel Setting cookies with AjaxBest Practices for Custom Helpers in Laravel 5iframe not reading cookies in ChromeMany questions about using Laravel PassportCan't get Auth object and cookies by consuming my own Laravel API
I have a project who authenticate the user using cookies like token_
and refreshToken_
, and a middleware who intercept my routes and verify if the user is logged or not.
In my middleware, when i need to renew the token_
I have the following code:
namespace AppHttpMiddlewareVerifyAccessToken
$cookie_name = "token_";
$cookie_value = $obj->access_token;
$expires_in = $obj->expires_in;
$time = time() + $expires_in; // 3600 = 1 hora
$path = "/";
$domain = env('COOKIE_DOMAIN');
setcookie($cookie_name, $cookie_value, $time, $path, $domain, false, true);
$cookie_name = "refreshToken_";
$cookie_value = $obj->refresh_token;
setcookie($cookie_name, $cookie_value, $time + 3600, $path, $domain, false, true);
return $next($request);
It works apparently fine, but the problem is:
After the middleware intercep my route and renew the cookie, the request proced to his controller, but there, I can't access the cookie using $_COOKIE['token_']
and I get an error, but if I look in the chrome's inspector, the cookie is there and reloading the page (F5) I can access the cookie in controller
Have a method for me access the cookie in controller without need to go to the view before?
laravel laravel-5 cookies
New contributor
add a comment |
I have a project who authenticate the user using cookies like token_
and refreshToken_
, and a middleware who intercept my routes and verify if the user is logged or not.
In my middleware, when i need to renew the token_
I have the following code:
namespace AppHttpMiddlewareVerifyAccessToken
$cookie_name = "token_";
$cookie_value = $obj->access_token;
$expires_in = $obj->expires_in;
$time = time() + $expires_in; // 3600 = 1 hora
$path = "/";
$domain = env('COOKIE_DOMAIN');
setcookie($cookie_name, $cookie_value, $time, $path, $domain, false, true);
$cookie_name = "refreshToken_";
$cookie_value = $obj->refresh_token;
setcookie($cookie_name, $cookie_value, $time + 3600, $path, $domain, false, true);
return $next($request);
It works apparently fine, but the problem is:
After the middleware intercep my route and renew the cookie, the request proced to his controller, but there, I can't access the cookie using $_COOKIE['token_']
and I get an error, but if I look in the chrome's inspector, the cookie is there and reloading the page (F5) I can access the cookie in controller
Have a method for me access the cookie in controller without need to go to the view before?
laravel laravel-5 cookies
New contributor
1
Possible duplicate of Can't set PHP cookie on the same page
– ceejayoz
Mar 6 at 14:44
laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');
– Mihai Crăiță
Mar 6 at 14:45
See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…
– ceejayoz
Mar 6 at 14:45
add a comment |
I have a project who authenticate the user using cookies like token_
and refreshToken_
, and a middleware who intercept my routes and verify if the user is logged or not.
In my middleware, when i need to renew the token_
I have the following code:
namespace AppHttpMiddlewareVerifyAccessToken
$cookie_name = "token_";
$cookie_value = $obj->access_token;
$expires_in = $obj->expires_in;
$time = time() + $expires_in; // 3600 = 1 hora
$path = "/";
$domain = env('COOKIE_DOMAIN');
setcookie($cookie_name, $cookie_value, $time, $path, $domain, false, true);
$cookie_name = "refreshToken_";
$cookie_value = $obj->refresh_token;
setcookie($cookie_name, $cookie_value, $time + 3600, $path, $domain, false, true);
return $next($request);
It works apparently fine, but the problem is:
After the middleware intercep my route and renew the cookie, the request proced to his controller, but there, I can't access the cookie using $_COOKIE['token_']
and I get an error, but if I look in the chrome's inspector, the cookie is there and reloading the page (F5) I can access the cookie in controller
Have a method for me access the cookie in controller without need to go to the view before?
laravel laravel-5 cookies
New contributor
I have a project who authenticate the user using cookies like token_
and refreshToken_
, and a middleware who intercept my routes and verify if the user is logged or not.
In my middleware, when i need to renew the token_
I have the following code:
namespace AppHttpMiddlewareVerifyAccessToken
$cookie_name = "token_";
$cookie_value = $obj->access_token;
$expires_in = $obj->expires_in;
$time = time() + $expires_in; // 3600 = 1 hora
$path = "/";
$domain = env('COOKIE_DOMAIN');
setcookie($cookie_name, $cookie_value, $time, $path, $domain, false, true);
$cookie_name = "refreshToken_";
$cookie_value = $obj->refresh_token;
setcookie($cookie_name, $cookie_value, $time + 3600, $path, $domain, false, true);
return $next($request);
It works apparently fine, but the problem is:
After the middleware intercep my route and renew the cookie, the request proced to his controller, but there, I can't access the cookie using $_COOKIE['token_']
and I get an error, but if I look in the chrome's inspector, the cookie is there and reloading the page (F5) I can access the cookie in controller
Have a method for me access the cookie in controller without need to go to the view before?
laravel laravel-5 cookies
laravel laravel-5 cookies
New contributor
New contributor
New contributor
asked Mar 6 at 14:40
ArthurUFArthurUF
31
31
New contributor
New contributor
1
Possible duplicate of Can't set PHP cookie on the same page
– ceejayoz
Mar 6 at 14:44
laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');
– Mihai Crăiță
Mar 6 at 14:45
See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…
– ceejayoz
Mar 6 at 14:45
add a comment |
1
Possible duplicate of Can't set PHP cookie on the same page
– ceejayoz
Mar 6 at 14:44
laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');
– Mihai Crăiță
Mar 6 at 14:45
See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…
– ceejayoz
Mar 6 at 14:45
1
1
Possible duplicate of Can't set PHP cookie on the same page
– ceejayoz
Mar 6 at 14:44
Possible duplicate of Can't set PHP cookie on the same page
– ceejayoz
Mar 6 at 14:44
laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');
– Mihai Crăiță
Mar 6 at 14:45
laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');
– Mihai Crăiță
Mar 6 at 14:45
See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…
– ceejayoz
Mar 6 at 14:45
See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…
– ceejayoz
Mar 6 at 14:45
add a comment |
2 Answers
2
active
oldest
votes
To read the value of Cookie in Laravel, do you need to use:
$token = Cookie::queued('token_');
dd($token->getValue());
https://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Cookie.html
Thanks, it worked.
– ArthurUF
Mar 7 at 19:56
add a comment |
Alright, with Cookie::queued('token_')
I receive the following object, but when I try access the "value" using:
$token = Cookie::queued('token_');
dd($token->value);
I get that error:
Cannot access protected property SymfonyComponentHttpFoundationCookie::$value
How can I access the value?
New contributor
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
ArthurUF is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55025690%2flaravel-cant-read-a-recently-created-cookie%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
To read the value of Cookie in Laravel, do you need to use:
$token = Cookie::queued('token_');
dd($token->getValue());
https://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Cookie.html
Thanks, it worked.
– ArthurUF
Mar 7 at 19:56
add a comment |
To read the value of Cookie in Laravel, do you need to use:
$token = Cookie::queued('token_');
dd($token->getValue());
https://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Cookie.html
Thanks, it worked.
– ArthurUF
Mar 7 at 19:56
add a comment |
To read the value of Cookie in Laravel, do you need to use:
$token = Cookie::queued('token_');
dd($token->getValue());
https://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Cookie.html
To read the value of Cookie in Laravel, do you need to use:
$token = Cookie::queued('token_');
dd($token->getValue());
https://api.symfony.com/3.0/Symfony/Component/HttpFoundation/Cookie.html
answered Mar 7 at 19:53
Leo MoraesLeo Moraes
16
16
Thanks, it worked.
– ArthurUF
Mar 7 at 19:56
add a comment |
Thanks, it worked.
– ArthurUF
Mar 7 at 19:56
Thanks, it worked.
– ArthurUF
Mar 7 at 19:56
Thanks, it worked.
– ArthurUF
Mar 7 at 19:56
add a comment |
Alright, with Cookie::queued('token_')
I receive the following object, but when I try access the "value" using:
$token = Cookie::queued('token_');
dd($token->value);
I get that error:
Cannot access protected property SymfonyComponentHttpFoundationCookie::$value
How can I access the value?
New contributor
add a comment |
Alright, with Cookie::queued('token_')
I receive the following object, but when I try access the "value" using:
$token = Cookie::queued('token_');
dd($token->value);
I get that error:
Cannot access protected property SymfonyComponentHttpFoundationCookie::$value
How can I access the value?
New contributor
add a comment |
Alright, with Cookie::queued('token_')
I receive the following object, but when I try access the "value" using:
$token = Cookie::queued('token_');
dd($token->value);
I get that error:
Cannot access protected property SymfonyComponentHttpFoundationCookie::$value
How can I access the value?
New contributor
Alright, with Cookie::queued('token_')
I receive the following object, but when I try access the "value" using:
$token = Cookie::queued('token_');
dd($token->value);
I get that error:
Cannot access protected property SymfonyComponentHttpFoundationCookie::$value
How can I access the value?
New contributor
New contributor
answered Mar 7 at 19:13
ArthurUFArthurUF
31
31
New contributor
New contributor
add a comment |
add a comment |
ArthurUF is a new contributor. Be nice, and check out our Code of Conduct.
ArthurUF is a new contributor. Be nice, and check out our Code of Conduct.
ArthurUF is a new contributor. Be nice, and check out our Code of Conduct.
ArthurUF is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55025690%2flaravel-cant-read-a-recently-created-cookie%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of Can't set PHP cookie on the same page
– ceejayoz
Mar 6 at 14:44
laravel handles cookies differently, retrieving a cookie is $value = $request->cookie('name');
– Mihai Crăiță
Mar 6 at 14:45
See also for a Laravel-specific answer/approach, particularly the "Laravel does support in-memory retrieval of cookies via queued()" bit: stackoverflow.com/questions/29836332/…
– ceejayoz
Mar 6 at 14:45