我有注册和登录系统与codeigniter,所有基本功能工作良好。
关于验证的工作原理,它将检查帐户的条件是否存在,令牌已过期,帐户已激活或帐户无效。下面是代码:
public function v_akun($email,$token)
{
$cek_email = $this->db->get_where('users',array('email' => $email))->num_rows();
if ($cek_email == 1) {
$cek_token = $this->db->get_where('users',array('token_email' => $token_email))->num_rows();
if ($cek_token == 1) {
$user_token = $this->db->get_where('users', ['email' => $email])->row_array();
if ($stdate - $user_token['created_token'] < (60 * 60 * 2)) {
$data = array(
'token_email' => '',
'validasi_email' => '1',
);
$where = array(
'email' => $email,
'token_email' => $token,
);
// Update to table
$this->m_data->update_data($where, $data,'users');
redirect('/home');
} else {
$where = array(
'email' => $email,
);
// Delete from table
$this->m_data->hapus_data($where, 'users');
echo "token expired";
}
} else {
echo "account already activated";
}
} else {
echo "invalid account";
}
}
当帐户无效时,它会显示该帐户不存在的正确消息,但除此之外,程序总是抛出"already"显示帐户已激活的状态。到这里:
else {
echo "account already activated";
}
我的条件反射语法有问题吗?非常感谢你的帮助。
我觉得你的语法有问题
$cek_token = $this->db->get_where('users',array('token_email' => $token_email))->num_rows();
if ($cek_token == 1) {
echo "account not activated";
} else {
echo "account already activated";
}
我认为问题是在$token_email
,这个变量不退出,实际的变量来自参数是$token
。
这就是为什么它总是检查空变量并返回零(0)行数。