PHP IF!= 0无效

时间:2014-04-26 17:08:09

标签: php

情景如下: 我有一个注册表单,用于创建激活码并将其分配给数据库中的文本字段。

文本字段:user_activation

分配激活码的代码。

p = new Password();
    $activation = $p->randomBase64String(100); // 100=length of string  
    $activation_code = $config->httpHost."/activation/?user=".$username."&hash=".$activation;

稍后在代码$ activation中分配给$ user_activation

new_user->user_activation = $activation;

电子邮件通过激活链接发送给用户,在点击时将长激活码更改为0(文本值)

activate_username =  $sanitizer->text($_GET['user']);
$activate_hash =  $sanitizer->text($_GET['hash']);

if(wire("users")->get($activate_username)->id) {
    if(strcmp(wire("users")->get($activate_username)->user_activation, $activate_hash) == 0 || wire("users")->get($activate_username)->user_activation == 0) {
        echo "Your account has been activated!<br><br>";
        $activate_user = wire("users")->get($activate_username);
        $activate_user->of(false);
        $activate_user->user_activation = "0";
        $activate_user->save();
    }

因此每个用户中的user_activation字段的值为0或长激活码。

登录后,我会检查此值以确定用户是否可以登录或是否仍然需要激活它们。

登录代码

//Check if submit is issued
if($input->post->login_submit) {

/*check for login before outputting markup
if($input->post->user && $input->post->pass) { */

    $user = $sanitizer->username($input->post->user);
    $pass = $input->post->pass; 

    if($user->user_activation != 0) {
    $login_errors .= "Sorry, but you need to activate your account!";
    $out .= $form;
    }


    elseif($session->login($user, $pass)) {
        // login successful
        $session->redirect("/"); 
        }

    else {
        $login_errors .= "Username or Password is incorrect";
        $out .= $form;
    }


}

else {
    $out .= $form;
}

问题是这似乎不起作用。任何想法为什么这不起作用。我尝试了以下,没有一个工作。

if($user->user_activation != 0) 
if($user->user_activation !== 0) 
if($user->user_activation != "0") 
if($user->user_activation !== "0") 

0 个答案:

没有答案