doulianqi3870 2014-06-07 09:46
浏览 37
已采纳

用户登录模型Codeigniter的错误

I am getting a couple of errors for my user model in my parent function. Just trying to make it this way. if $user_query->num_rows and also my isset session user-data.

Fatal error: Cannot use isset() on the result of a function call (you can use "null !== func()" instead) in C:\xampp\htdocs\codeigniter-cms-1\admin\application\modules\backend\models\user\user_model.php on line 11

and

Parse error: syntax error, unexpected 'if' (T_IF) in C:\xampp\htdocs\codeigniter-cms-1\admin\application\modules\backend\models\user\user_model.php on line 15

private $user_id;
private $username;
private $permission = array();

public function __construct() {
parent::__construct();
if(isset($this->session->set_userdata('user_id')) { // Error

$user_query = $this->db->query("SELECT * FROM " . $this->input->post('db_prefix') . "user WHERE user_id = '" . (int)$this->session->userdata('user_id') . "' AND status = '1'")

if($user_query->num_rows == 1) { // Error
    $this->user_id = $user_query->row('user_id');
    $this->username = $user_query->row('username');
    $this->db->query("UPDATE " . $this->input->post('db_prefix') . "user SET ip = '" . $this->input->ip_address() "' WHERE user_id = '" . (int)$this->session->userdata('user_id') . "'");
    $user_group_query = $this->db->query("SELECT * FROM " . $this->input->post('db_prefix')  . "user_group WHERE user_group_id = '" . (int)$query->row('user_group_id') . "'");
    } else {
       $this->logout();
    }
  }
}

public function login($username, $password) {
    // Still Working On This Part
}

public function logout() {
    $this->session->unset_userdata('user_id');

    $this->user_id = '';
    $this->username = '';
}
  • 写回答

2条回答 默认 最新

  • dqjl0906 2014-06-07 09:49
    关注

    you missed (.) in below line

    change this code:

    $this->db->query("UPDATE " . $this->input->post('db_prefix') . "user SET ip = '" . $this->input->ip_address() "' WHERE user_id = '" . (int)$this->session->userdata('user_id') . "'");
    

    To

    $this->db->query("UPDATE " . $this->input->post('db_prefix') . "user SET ip = '" . $this->input->ip_address()."' WHERE user_id = '" . (int)$this->session->userdata('user_id') . "'");
    

    Update

    private $user_id;
    private $username;
    private $permission = array();
    
    public function __construct() {
    parent::__construct();
    if(isset($this->session->set_userdata('user_id'))) { // here you missed close bracket
    
    $user_query = $this->db->query("SELECT * FROM  " . $this->input->post('db_prefix') . "user WHERE user_id = '" . (int)$this->session->userdata('user_id') . "' AND status = '1'")
    
    if($user_query->num_rows() == 1) { // num rows is function
        $this->user_id = $user_query->row('user_id');
        $this->username = $user_query->row('username');
        $this->db->query("UPDATE " . $this->input->post('db_prefix') . "user SET ip = '" . $this->input->ip_address()."' WHERE user_id = '" . (int)$this->session->userdata('user_id') . "'");
        $user_group_query = $this->db->query("SELECT * FROM " . $this->input->post('db_prefix')  . "user_group WHERE user_group_id = '" . (int)$query->row('user_group_id') . "'");
        } else {
           $this->logout();
        }
      }
    }
    
    public function login($username, $password) {
        // Still Working On This Part
    }
    
    public function logout() {
        $this->session->unset_userdata('user_id');
    
        $this->user_id = '';
        $this->username = '';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据