background image

                    session(null);
                } else {
                    $map = array();
                    $map['id'] = array('eq', $id);
                    $data['lasttime'] = time();
                    $data['lastip'] = $ip;
                    $online->where($map)->save($data);
                }
            } else { // 

  

不是登录用户 游客

                unset($map);
                $map['lastip'] = array('eq', $ip);
                $id = $online->where($map)->getField('id');
                //dump($id);
                if (empty($id)) { // 

 

不存在在线记录, 则添加

                    $data = array();
                    $data['uid'] = 0;
                    $data['account'] = 'Guest';
                    $data['nickname'] = '游客';
                    $data['lasttime'] = time();
                    $data['lastip'] = $ip;
                    $online->add($data);
                } else {
                    $map = array();
                    $map['id'] = array('eq', $id);
                    $data['lasttime'] = time();
                    $data['lastip'] = $ip;
                    $online->where($map)->save($data);
                }
            }
        }
    }
 }
 ?>
3,在具体登录的地方添加如下代码:
// 登录检测
    public function checkLogin() {
        // $this->redirect($url);
        $username = strtolower($this->_param('usr'));
        $pwd = $this->_param('pwd');
        $url = $this->_param('url'); // 目标地址
        $is_error = false;
        if (empty($username) or empty($pwd)) {
            $this->assign('error_msg', '用户名和口令不能为空');
            $is_error = true;