PHP阅读使用setcookie()创建的Cookie [英] PHP Read cookies created with setcookie()

查看:108
本文介绍了PHP阅读使用setcookie()创建的Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

手册


Cookie在下次加载页面时不会显示,该页面对于

应该可见。

意味着使用<在下一页加载之前,在 $ _ COOKIE 中将无法访问code> setcookie 。有这方面的工作吗?有没有办法检测在 重载的 p>我不能修改当前代码库中 setcookie 调用附近的代码。所以像这样的解决方案不会工作:

  setcookie('test','my test value'); 
$ _COOKIE ['test'] ='我的测试值';


解决方案

_COOKIES超全局是作为脚本初始化的一部分创建的,然后由PHP留下。因此,以后在脚本中创建的任何cookie都不会奇迹般地显示在数组中,因为它们在初始化时不存在。



您可以使用 runkit_function_redefine() ,但如果你不是很小心,你可以打开一个受伤的世界。


From the manual:

Cookies will not become visible until the next loading of a page that the cookie should be visible for

Meaning that a cookie created with setcookie will not be accessible in $_COOKIE until the next page load. Is there a work around for this? Is there a way to detect the cookies created with setcookie in PHP without a reload?

I can't modify the code near the setcookie call in the current codebase. So an solution like this won't work:

setcookie('test', 'my test value');
$_COOKIE['test'] = 'my test value';

解决方案

The _COOKIES superglobal is created as part of the script's initialization, and then is left alone by PHP. As such, any cookies you create later in the script will not magically appear in the array, as they were not present at initialization time.

You can override the built-in setcookie functionality with runkit_function_redefine(), but if you're not very careful, you can open yourself up to a world of hurt.

这篇关于PHP阅读使用setcookie()创建的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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