gpt4 book ai didi

php - 如何使用 MAMP + MacOSx + PHP 在本地主机上设置 cookie?

转载 作者:可可西里 更新时间:2023-10-31 22:08:40 26 4
gpt4 key购买 nike

我在我的 Mac 笔记本电脑上开发,我使用 MAMP。我正在尝试使用 PHP 设置 cookie,但我做不到。我离开了域,我尝试使用“\”作为域。没有运气。

setcookie("username", "George", false, "/", false);
setcookie("name","Joe");

我一定遗漏了一些明显的东西。我需要一个快速简单的解决方案。有吗?

我没有做任何花哨的事情,只是加载(通过 MAMP)页面, http://localhost:8888/MAMP/lynn/setcookie.php

该脚本的顶部有 setcookie 代码,甚至在编写 HTML 标记之前。 (尽管我也在 BODY 中尝试过)。我在各种浏览器中加载页面,然后打开 cookie 列表。我知道浏览器接受 cookie,因为我在列表中看到了当前的 cookie。只是不是我的新的。

最佳答案

来自文档:

setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including and tags as well as any whitespace.

是吗?

编辑:

你能看到服务器发送的 cookie 吗?通过使用 Firefox 扩展 Tamper Data 或 telnet?你能看到它在下一个请求时被浏览器发回吗? setcookie() 的返回值是多少?它不是在所有浏览器中都有效,还是仅在某些浏览器中有效?

关于php - 如何使用 MAMP + MacOSx + PHP 在本地主机上设置 cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/631819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com