我正在尝试创建包含在客户端加密的凭据的cookie,目前我只是使用php中的set cookie函数以json格式存储数组。但当我回读cookie时,它与我设置的不一样。 使用服务器中的setcookie函数设置cookie。
$credential = array();
$credential['id'] = $result[0]['id'];
$credential['username'] = $_POST['_username'];
$credential['password'] = $_POST['_password'];
$credential['auth'] = TRUE;
$_SESSION['id'] = $credential['id'];
$_SESSION['username'] = $credential['username'];
$_SESSION['passsword'] = $credential['password'];
$_SESSION['auth'] = TRUE;
$this->setcookie("cr", $this->encode($credential));
function setcookie($name, $value) {
$cookiedata = $value;
return setcookie($name, serialize($cookiedata), time()+3600*24*1000, '/');
}
客户端的尝试了以下方法,但没有一个导致干净的cookie
console.log(JSON.parse(JSON.stringify($.cookie('cr'))));
console.log(JSON.stringify($.cookie('cr')));
都导致了
62::S" {" ID":" 6""用户名":" yashwanth"&# 34;密码":" ASD"" AUTH":真}&#34 ;;
预期
{" ID":" 6""用户名":" yashwanth""密码":& #34; ASD"" AUTH":真};