I have registration and login system with codeigniter, all basic functions work fine.
On how the verification works, it will check the condition of the account whether the account exists, the token has expired, the account has been activated, or the account is invalid. Here's the code:
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";
}
}
When the account is invalid, it displays the correct message that the account does not exist, but other than that, the program always throws an "already" state which says the account has been activated. To here:
else {
echo "account already activated";
}
Is there something wrong in my conditioning syntax? Thank you very much for the help.
CodePudding user response:
I think there is some error in your syntax at
$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";
}
I think the problem is in $token_email
, that this variable does not exit, the actual variable coming from parameters is $token
.
So that is why it always check for an empty variable and returns zero (0) number of rows.