- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
所以根据我对 PHP 和 cookie 的理解,如果我使用 setcookie()
函数,那么我会得到一个自动 url 编码的 cookie。当我转到 $_COOKIE
数组时,我应该取回 cookie,自动进行 url 解码。问题是,当我查看 $_COOKIE
时,它似乎对 cookie 进行了两次解码。
假设我有一个值为“Name|ID|Email”的 cookie,例如:
Joe|123|my+email@somewhere.com
这将被编码为:
Joe%7C123%7Cmy%2Bemail%40somewhere.com
请注意,加号是经过编码的,因此理论上,如果我对其进行解码,我应该将其取回。因为这是在 $_COOKIE
中自动完成的,所以我应该恢复原来的状态。但相反,我回来了:
Joe|123|my email@somewhere.com
注意加号所在的空间。如果我在 cookie 上运行额外的 urldecode()
,这就是我所期望的。但我不是,所以我不知道为什么我会得到一个空间而不是加号。
另一个有趣的转折。页面刷新似乎产生了正确的输出。知道为什么它会这样吗?
仅供引用,为了设置初始 cookie,我使用 javascript 和 escape()
脚本来生成编码字符串。这可能是 javascript 和 PHP 之间的交接问题吗?
想法将不胜感激。
最佳答案
值得注意的是,“%20”和“+”都是空格字符的有效编码。根据关于 URL encoding 的维基百科文章(强调):
When data that has been entered into HTML forms is submitted, the form field names and values are encoded and sent to the server in an HTTP request message using method GET or POST, or, historically, via email. The encoding used by default is based on a very early version of the general URI percent-encoding rules, with a number of modifications such as newline normalization and replacing spaces with "+" instead of "%20". The MIME type of data encoded this way is application/x-www-form-urlencoded, and it is currently defined (still in a very outdated manner) in the HTML and XForms specifications.
更具体地与 PHP 和 JavaScript 相关,请参阅此问题的最佳答案:
关于php - 为什么 PHP 将 $_COOKIE 中的加号替换为空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14383715/
我花了一些时间试图追踪 a particular Laravel bug 的根本原因,因为最初的 GitHub 问题在没有解决的情况下被关闭。 经过一段时间的试验,我发现 session 正在重新生成
我遇到了一个奇怪的问题。我正在将 AJAX 发送到设置 $_COOKIE['cookieName'] 的 PHP 文件然后我在主文件中回显该 cookie。 问题:如果处理 AJAX 的 PHP 文件
我正在网页上工作。以下代码在 single.php 中。 首先,如果有人打开页面/帖子 + 1,我会计算每次。 = 3){ //If its more than 3, cookie reset
我试图在 cookie 中插入多个值,但我只能存储一个值。听到是我的代码。 "> submit 和我的 result4.php '; print_r($_COOKIE["lastvi
假设我有一个网站 www.mysite.com。 $_COOKIE 数组是否可以包含由 www.mysite.com 以外的域设置的 cookie,如果我使用 $_COOKIE > 通过域 www.m
我已经下载了这样的脚本: $QUERY_STRING="login"; if (file_exists("passwd.dat") && $QUERY_STRING != ""): requ
我将一个 cookie 分配给一个变量: $user_cookie = $_COOKIE["user"]; 我如何检查 $user_cookie 是否收到了一些值? 我应该使用 if (empty($
大约几周前,我在创建登录页面时了解了 $_SESSION。我可以成功登录并将其与变量一起使用。目前我正在尝试理解 $_SESSION 和 $_COOKIE。如果我错了请纠正我,我可以在登录和移动页面时
我是网络应用程序和 PHP 的新手。 我正在尝试获取尚未创建的 cookie,我的意思是,当我尝试加载查找不存在的 cookie 的页面时出现错误,我尝试通过尝试摆脱它/catch 但没有成功。这是我
所以我正在为自己创建一个博客,并且为了给自己设置一个 cookie 的管理员权限。 我已经手动检查了它的存在。 我已经使用 apache 服务器在我的笔记本电脑上测试了代码,代码工作正常。 我有两个p
在 TypoScript 中可以获取环境变量 HTTP_COOKIE_VARS (已弃用): 10 = TEXT 10.data = global : HTTP_COOKIE_VARS | some_
我有一个 JavaScript 可以保存复选框状态,将其放入 cookie 中,然后在我的表单中重新填充我的复选框。我现在想做的是用 php 将一堆“if 语句”放在一起,然后为那些“true”的字符
我目前正在使用 PHP 制作一个简单的登录系统,何时编写此内容 $sql = "SELECT * FROM logintoken WHERE token ='".$_COOKIE['SNID']."'
我不记得过去使用 Cookies 时遇到过很多问题,但我一直在尝试并遇到了一些意想不到的结果。 (我在本地主机上运行,因此我的域设置) "; echo "Cookie equals: ".$_CO
我正在尝试在 PHP 中调用 setcookie() 函数后立即访问 cookie 的值(使用 $_COOKIE)。当我这样做时, $_COOKIE['uname'] 没有设置。为什么? 但请注意,$
大多数情况下,我使用过$_SESSION,但是在阅读有关 Session 的内容时,我得到的术语很少 $_ENV & $_COOKIE。 我不清楚什么时候使用哪个,我对我可以使用它们的情况感到困惑。那
我遇到跨域 AJAX 请求的问题。 此问题涉及三台服务器。我们可以称它们为 A1、A2 和 B。 A1 和 A2 运行相同的应用程序代码。它们是同一 Web 应用程序的两个暂存实例。 B 是另一个网络
$_SERVER['HTTP_COOKIE'] 和 $_COOKIE 有什么区别? 为什么 $_SERVER['HTTP_COOKIE'] 没有记录在 PHP 手册中? 我正在创建一个用于管理 coo
所以根据我对 PHP 和 cookie 的理解,如果我使用 setcookie() 函数,那么我会得到一个自动 url 编码的 cookie。当我转到 $_COOKIE 数组时,我应该取回 cooki
$user = $_COOKIE["username"]; $admin = $db->query(" SELECT * FROM users WHERE us
我是一名优秀的程序员,十分优秀!