简体   繁体   English

如何在wordpress网站上设置cookie?

[英]How to setcookie on wordpress site?

I have problem with seting and reading cookie on wordpress site. 我在wordpress网站上设置和读取cookie时遇到问题。

Here is what I'm doing: 这是我在做什么:

1.Sending over js id to php 1.通过js id发送到php

ajax.js ajax.js

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

});

ajax.php ajax.php

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

2.When I read that cookie ( echo $_COOKIE['myids']; )in /wp-content/themes/mytheme/ index.php 2.当我在/ wp-content / themes / mytheme / index.php中读取该cookie(echo $ _COOKIE ['myids'];)时

I get value which I set and that is ok but when i try to read that cookie in /wp-content/themes/mytheme/ajax.php I am not getting cookie. 我得到设置的值,没关系,但是当我尝试在/wp-content/themes/mytheme/ajax.php中读取该cookie时,我没有得到cookie。

What I am doing wrong? 我做错了什么?

解决方案:将ajax.php放在根目录(/ajax.php)中,然后它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM