【发布时间】:2014-06-02 23:01:28
【问题描述】:
好吧,我已经尝试了所有我能想到的方法,而且我已经走到了尽头!
基本上我正在尝试设置两个 cookie 'user' 和 'usertype'。 现在,当我将 cookie 用户设置为实际用户名时,用户类型也会按照我的意愿设置。
但是,如果我将 cookie 'user' 设置为表中用户的 id,那么由于某种原因,usertype cookie 没有设置。
代码很简单,就是:
setcookie('user',$row['id']);
setcookie('usertype',$row['type']);
header('Location:index.php');
这样它不会设置用户类型,但会正确设置用户,但是如果我也简单地更改它:
setcookie('user',$row['username']);
setcookie('usertype',$row['type']);
header('Location:index.php');
那么两个cookies都设置正确了。
$row 的 var_dump 也可以作为参考:
array (size=6)
'id' => string '2' (length=1)
'name' => string 'Test User' (length=9)
'pass' => string '098f6bcd4621d373cade4e832627b4f6' (length=32)
'username' => string 'test' (length=4)
'email' => string 'test@test.com' (length=13)
'type' => string '2' (length=1)
我只是不明白第一种方式如何在重定向到 index.php 之前只设置用户 cookie,而第二种方式如何设置两个 cookie。任何帮助将不胜感激。
【问题讨论】: