gpt4 book ai didi

php - 无法在 localhost 上的 php 中读取 cookie

转载 作者:行者123 更新时间:2023-12-04 20:26:45 24 4
gpt4 key购买 nike

虽然我可以在浏览器中看到,但 PHP 没有读取 cookie。

//i set cookie in localhost/site/classes/php/user
setcookie("liu", $result[0]['user_id'], time() + 60 * 60 * 24 * 30, "/");
//trying to access it in localhost/site/index.php
$loggedInUser = $_COOKIE['liu'];

最佳答案

如果您在 localhost 上运行,则应将 cookie 域显式设置为 false

你可以试试:

setcookie("liu", $result[0]['user_id'], time() + 60 * 60 * 24 * 30, "/", false);

在此处进一步了解:Cookies on localhost with explicit domain

关于php - 无法在 localhost 上的 php 中读取 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16779204/

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