Laravel 4:读取由 javascript 设置的 cookie [英] Laravel 4: reading cookies set by javascript

查看:18
本文介绍了Laravel 4:读取由 javascript 设置的 cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 javascript 设置 cookie,我将如何使用 Laravel 4 读取它?

If I set a cookie with javascript, how would I read it using Laravel 4?

我问的原因是文档说:

All cookies created by the Laravel framework are encrypted and signed 
with an authentication code, meaning they will be considered invalid 
if they have been changed by the client.

推荐答案

只需使用原生 PHP 命令检索 cookie:$_COOKIE['cookie'])

Just use the native PHP command to retrieve cookies: $_COOKIE['cookie'])

或者你可以通过 AJAX 命令设置 cookie(而不是 JS 自己做) - 并让 Laravel 代表它设置 JS 提供的 cookie?

Or perhaps you can set the cookie via an AJAX command (rather than JS doing it itself) - and have Laravel set the cookie supplied by JS on its behalf?

此链接确认通过 AJAX 设置 cookie - 它只是一个变体.

This link confirms setting cookies via AJAX - it will just be a variation of that.

这篇关于Laravel 4:读取由 javascript 设置的 cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆