【问题标题】:How to setcookie on wordpress site?如何在 wordpress 网站上设置cookie?
【发布时间】:2013-05-21 18:40:21
【问题描述】:

我在 wordpress 网站上设置和读取 cookie 时遇到问题。

这是我正在做的事情:

1.通过js id发送到php

ajax.js

jQuery.post("/wp-content/themes/mytheme/ajax.php", {post_id: post_id}, function(data){

});

ajax.php

setcookie('myids', $_COOKIE['myids'].$_POST['post_id'], time()+3600*24*100, '/');

2.当我在 /wp-content/themes/mytheme/index.php 中读取那个 cookie ( echo $_COOKIE['myids']; )

我得到了我设置的值,这没关系,但是当我尝试在 /wp-content/themes/mytheme/ajax.php 中读取该 cookie 时,我没有得到 cookie。

我做错了什么?

【问题讨论】:

  • 你还没有发布你正在做什么(代码方面)来读取 cookie,所以我们不能开始说你在做什么错误。
  • 我已更改问题
  • /wp-content/themes/mytheme/ajax.php 看到的$_COOKIE 的内容是什么?

标签: php wordpress cookies


【解决方案1】:

解决方法:将 ajax.php 放在根目录下( /ajax.php )就可以了。

【讨论】:

    猜你喜欢
    • 2022-12-11
    • 2012-03-10
    • 2020-07-25
    • 2020-11-18
    • 2017-10-02
    • 1970-01-01
    • 2016-08-28
    • 2018-11-15
    • 2012-08-01
    相关资源
    最近更新 更多