Php 有多少用户在codeigniter中与同一用户登录?

Php 有多少用户在codeigniter中与同一用户登录?,php,mysql,codeigniter,frameworks,Php,Mysql,Codeigniter,Frameworks,我的应用程序有问题“多用户可以记录同一用户我需要防止这个问题,我希望能帮助我。” 我的代码: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Login extends CI_Controller { public function index() { $posts = $this->input->post(); $name = $this-&g

我的应用程序有问题“多用户可以记录同一用户我需要防止这个问题,我希望能帮助我。” 我的代码:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
public function index()
{
    $posts = $this->input->post();
    $name  = $this->input->post('name');
    $pass  = $this->input->post('pass');   

    if(isset($posts['submit']))
    {
        $this->load->library('form_validation');

        $this->form_validation->set_rules('name', 'name ', 'trim|required');
        $this->form_validation->set_rules('pass', 'pass ', 'trim|required');    

        if($this->form_validation->run())
        {
            $this->load->model("users_model");
            $res = $this->users_model->auth($name,$pass); 
            if(!empty($res))
            {
                foreach($res as $r)
                { 
                    if($r->active == 0)
                    {
                        $err = '<h4 class="alert alert-danger"> error loggin           

为了确保用户不会登录两次,您可以将会话存储在中,然后检查用户是否已登录。如果是,请删除旧用户并允许登录,或者显示确认消息以确定是否终止剩余会话。我建议自动使会话。

我的建议是请编写单独的登录控制器。您的登录控制器应如下所示

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Controllername extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        $this->load->model("users_model");

        if(!empty($this->session->userdata('userid');))
        {
            /*if any try to login again if they already logged in make them to redirect to 
               any other page you want*/
        }
    }

    public function login()
    {
        $this->load->library('form_validation');

        $this->form_validation->set_rules('name', 'name ', 'trim|required');
        $this->form_validation->set_rules('pass', 'pass ', 'trim|required');

        if($this->form_validation->run())
        {

            $res = $this->users_model->auth($name,$pass); 
            if(!empty($res))
            {
                //if the userdata matches then set the session while login

                $this->session->set_userdata('userid', $res[0]->userid );

               //after login redirect the user to where you want

            } 

         }
    }

}

什么意思…你想阻止一个用户从多个设备登录..最简单的方法是在数据库的用户表中设置登录状态,如果用户已经登录,则将其设置为1,并根据每个登录的用户凭据检查登录状态。例如:用户名:john and pass=123123ser logged此用户不能记录其他同一用户,这就是我的意思