如何在javascript中设置cookie并在php代码中检索它

时间:2015-11-20 05:08:20

标签: javascript php wordpress cookies

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     如果(isset($ _ COOKIE [ 'buttn']))      {//做点什么      }

1 个答案:

答案 0 :(得分:1)

试试这个, 在javascript中

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

在php中

print_R($_COOKIE);