【问题标题】:how to set cookie in javascript and retrieve it in php code [duplicate]如何在javascript中设置cookie并在php代码中检索它[重复]
【发布时间】:2016-02-22 12:15:22
【问题描述】:
function CheckIfChecked(){
   var strChoices = "";
   var chk = document.getElementsByName("check_list[]"); 
   var chklength = chk.length;
   var e = document.getElementById("select_bulk"); 
   var strUser = e.options[e.selectedIndex].value;        
   var buttn = document.getElementById("bulk");
   Cookies.set(chk, e, strUser, butttn);}

// 想在下面的 php 代码中检索这个 cookie if(isset($_COOKIE['buttn'])) { // 做点什么
}

【问题讨论】:

  • 这个代码是什么,Cookies.set(chk, e, strUser, butttn);?
  • @Ramanlfc 如果代码不正确,请解释代码有什么问题。
  • 我想在 javascript 中设置 cookie 我试过 Cookies.set(chk, e, strUser, butttn);但不起作用

标签: javascript php wordpress cookies


【解决方案1】:

试试这个, 在javascript中

var key = "aaa"
var val = "bbb"
document.cookie = key + "=" + val;

在php中

print_R($_COOKIE);

【讨论】:

  • 如何在abvoe代码中获取php中变量key的cookie
  • 在 php 中使用 $_COOKIE['aaa'] 获取上述代码...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多