English 中文(简体)
统一数据库会议
原标题:Unserialize Database Session Codeigniter

我确实有一个与密码数据库会议有关的问题。

为了缩短发言时间,我不想有同一份全权证书(口头/口头)。

第一个核查由数据库中的用户名/带照片进行。

我的法典

function index()
{
    // Load Model.
    $this->load->model( membres_model );

    // Check if the user is already logged
    if($this->session->userdata( alias ) || $this->session->userdata( logged ))
    {
        //Redirect if he is logged.
        redirect( membres/ );
    }
    // If the form has been sent.   
    if($this->input->post( submit ))
    {           
        // Trim data
        $this->form_validation->set_rules( alias , Nom d utilisateur , trim|required|xss_clean );
        $this->form_validation->set_rules( motdepasse , Mot de passe , trim|required|xss_clean );

        if($this->form_validation->run())
        {
            // check verification in the model
            if($this->membres_model->verification_connexion($this->input->post( alias ),$this->input->post( motdepasse )))
            {
                // Set userdata variables
                $data = array(
                     alias      =>  $this->input->post( alias ),
                     addr_ip    =>  $_SERVER[ REMOTE_ADDR ],
                     hote       =>  gethostbyaddr($_SERVER[ REMOTE_ADDR ]),
                     logged     =>  true
                );

                    /****************************************
                    I Want to verify if the membres is already logged if another one want to use the                        same login/password of the logged on. but I don t know how to verify in the                         ci_sessions
                    *****************************************/

                    // start session
                    $this->session->set_userdata($data);
                    // Redirection sur l espace membre apres la creation de la session.
                    redirect( membres/ );
            }
            else {
                // if return false
                $data[ error ] =  Mauvais identifiants ;
                $data[ contenu ] =  connexion/formulaire ;
                $this->load->view( includes/template ,$data);
            }
        } 
        else {

            $data[ contenu ] =  connexion/formulaire ; // La variable vue pour loader dans le template.
            $this->load->view( includes/template ,$data);
        }

    } 
    else {

        $data[ contenu ] =  connexion/formulaire ; // La variable vue pour loader dans le template.
        $this->load->view( includes/template ,$data);
    }

}
}

我知道我确实必须利用会议周期。 我可以拿到这些阵列,但我不知道如何将数据与挂牌用户进行比较。 没有人能够帮助我?

问题回答

仅仅在会议桌上加上另一栏(“用户_id”),这样你就可以用单一和简单的盘问加以核对。 <>代码>unserialize()(如果需要的话),通常是一种非常缓慢的职能,在会议桌上核对每行都会成为一个问题。

但是,......在此,《识别法》如何将其届会数据推向外:

    protected function _unserialize($data)
    {
            $data = @unserialize(strip_slashes($data));

            if (is_array($data))
            {
                    array_walk_recursive($data, array(&$this,  _unescape_slashes ));
                    return $data;
            }

            return (is_string($data)) ? str_replace( {{slash}} ,  \ , $data) : $data;
    }

......并在此呼吁:

    protected function _unescape_slashes(&$val, $key)
    {
            if (is_string($val))
            {
                    $val= str_replace( {{slash}} ,  \ , $val);
            }
    }

如果得不到保护,你可以直接使用这些图书馆,但......你更有理由扩大会议图书馆,而不是独自执行。

你可以尝试这样的事情:

$sessions = "SELECT * FROM ci_sessions"; // return as object

        foreach($sessions as $sess)
        {
            foreach(unserialize($sess->user_data) as $k => $v)
            {
                if($k ===  alias  AND isset($v))
                {
                    return true;
                }
            }
        }

OR作为你可能希望使用cookie的一种替代办法

public function _before_check($alias) // alias should have UNIQUE constraint
{
    return ($this->input->cookie( my_cookie_ .$alias, TRUE)) ? TRUE : FALSE;
}

在你的表格验证中,你在检查前做事!

if($this->_before_check($alias))
{
   //already logged In
}
else
{
  //log them in AND set your cookie
}

<>Con:如果他们试图通过新的计算机登录,他们可以绕过这一条。

<>:您可能希望确定您的任期届满时间,以便与您的会议时间相吻合,即:2小时(7200)。





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签