【问题标题】:if statement not working in codeigniterif 语句在 codeigniter 中不起作用
【发布时间】:2014-04-18 01:22:39
【问题描述】:

我正在为我的网站建立一个登录我有这个 if 语句:

$application = 'home';
    $this->user_model->loggedin() == TRUE || redirect($application);


    $rules = $this->user_model->_rules;
    $this->form_validation->set_rules($rules);
    if ($this->form_validation->run() !== FALSE) {
          if ($this->user_model->login() !== FALSE) {
            redirect('home');
            echo 'success';
        }  else {
           echo 'fail'; 
        }

    }

由于某种原因,当我提出条件 == FALSE 时它不会运行 else,这将输入错误的电子邮件和密码。无论哪种方式,我都会收到消息成功我在这里遗漏了什么吗?

这里是 user_model 中的登录功能,如果有帮助,想不出这个,任何帮助将不胜感激。

public function login() {
    $user = $this->get_by(array(
        'email_address' => $this->input->post('email_address'),
        'password' => $this->hash($this->input->post('password'))
            ), TRUE);

    if (count($user)) {
        // log in user
        $data = array(
            'first_name' => $user->first_name,
            'last_name' => $user->last_name,
            'email_address' => $user->email_address,
            'id' => $user->id,
            'loggedin' => TRUE,
        );
      $this->session->set_userdata($data);   
    }

}

【问题讨论】:

    标签: php codeigniter if-statement


    【解决方案1】:

    您的login() 函数没有返回任何内容。您要么打算根据登录尝试是否成功(最有可能)返回 TRUE 或 FALSE 值,要么要针对会话用户数据进行测试。

    【讨论】:

    • @user3035984 有时只需要多一双眼睛
    • 在你凌晨 4 点起床的时候,眼睛会出卖你:D
    猜你喜欢
    • 2017-05-22
    • 1970-01-01
    • 2012-07-16
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 2016-04-25
    • 1970-01-01
    相关资源
    最近更新 更多