21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
session_start();
function set_login_cookie($u,$t){
$uid = $u["userid"];
$uname = $u["username"];
$uck = $u["userck"];
cookie("userid",$uid,$t);//无效
cookie("username",$uname,$t);//无效
cookie("userck",$uck,$t);//无效
cookie("aaaa","aaaa",$t);//有效,有效,有效
}
function cookie($n,$v,$t){
echo "[".$n."]=[".$v."] ".$t."\n";
setcookie($n,$v,$t,"/");
$_COOKIE[$n] = $v;
}
$a=[];
$a["userid"]=1;
$a["username"]="a";
$a["userck"]="fasdf";
echo "<pre>
------------- set data ---------------
";
set_login_cookie($a,time()+6000);
echo "------------Cookie data---------------
";
var_dump($_COOKIE);
?>
------------- set data ---------------
[userid]=[1] 1555398360
[username]=[a] 1555398360
[userck]=[fasdf] 1555398360
[aaaa]=[aaaa] 1555398360
------------Cookie data---------------
array(5) {
["PHPSESSID"]=>
string(26) "chmb3jj4dd3997d80pctmhm3o5"
["aaaa"]=>
string(4) "aaaa"
["userid"]=>
int(1)
["username"]=>
string(1) "a"
["userck"]=>
string(5) "fasdf"
}