我能够echo session_id()
以及所有这些。但我似乎无法进入表格的session_id()
。
这是我的功能:
public function login($email, $password) {
$row = DB::getInstance()->get('users', array('email', '=', $email));
$password = $row->first()->user_salt . $password;
$password = $this->hashData($password);
$is_active = (boolean) $row->first()->is_active;
$is_verified = (boolean) $row->first()->is_verified;
if ($email == $row->first()->email && $password == $row->first()->password) {
$match = true;
} else {
$match = false;
}
if ($match == true) {
if ($is_active == true) {
if ($is_verified == true) {
$random = $this->randomString();
$token = $_SERVER['HTTP_USER_AGENT'] . $random;
$token = $this->hashData($token);
$_SESSION['token'] = $token;
$_SESSION['user_id'] = $row->first()->id;
$userid = $row->first()->id;
$session = session_id();
echo $session;
$deleteold = DB::getInstance()->delete('active_users', array('user_id', '=', $userid));
$insertnew = DB::getInstance()->insert('active_users', array(
'user_id' => $userid,
'session_id' => $session,
'token' => $token
));
if ($insertnew != false) {
return 0;
}
return 3;
} else {
// NOT VERIFIED
return 1;
}
} else {
// NOT ACTIVE
return 2;
}
}
正如您所看到的,我已经声明了$session = session_id();
并且我的回显显示了没有问题的ID,但是当我插入数据库时,存储的唯一值是0.为什么我无法存储session_id()
?
答案 0 :(得分:2)
session_id()
返回一个字符串,但它似乎在数据库中保存为整数。如果在db模式中将session_id的类型更改为varchar,它应该可以工作。