src/bbn/user.php
private function _init_session(){

    // Getting or creating the session is it doesn't exist yet
    /** @var user\session */
    $this->session = user\session::get_instance();
    if ( !$this->session ){
      $this->session = new user\session();
    }

    /** @var int $id_session The ID of the session row in the DB */
    if ( $id_session = $this->get_id_session() ){
      $this->sess_cfg = json_decode($this->db->select_one(
        $this->class_cfg['tables']['sessions'],
        $this->class_cfg['arch']['sessions']['cfg'],
        [$this->class_cfg['arch']['sessions']['id'] => $id_session]
      ), true);
    }
    else{

      /** @var string $salt */
      $salt = self::make_fingerprint();

      /** @var string $fingerprint */
      $fingerprint = self::make_fingerprint();


      /** @var array $p The fields of the sessions table */
      $p =& $this->class_cfg['arch']['sessions'];

      $this->sess_cfg = [
        'fingerprint' => $this->get_print($fingerprint),
        'last_renew' => time()
      ];

      // Inserting the session in the database
      if ( $this->db->insert($this->class_cfg['tables']['sessions'], [
        $p['sess_id'] => $this->session->get_id(),
        $p['ip_address'] => $this->ip_address,
        $p['user_agent'] => $this->user_agent,
        $p['opened'] => 1,
        $p['last_activity'] => date('Y-m-d H:i:s'),
        $p['creation'] => date('Y-m-d H:i:s'),
        $p['cfg'] => json_encode($this->sess_cfg)
      ]) ){
        // Setting the session with its ID
        $id_session = $this->db->last_id();
        $this->session->set([
          'fingerprint' => $fingerprint,
          'tokens' => [],
          'id_session' => $id_session,
          'salt' => $salt
        ], self::$sn);
        $this->save_session();
      }
      else{
        $this->set_error(16);
      }
    }
    return $this;
  }
private function _init_session(){

    // Getting or creating the session is it doesn't exist yet
    /** @var user\session */
    $this->session = user\session::get_instance();
    if ( !$this->session ){
      $this->session = new user\session();
    }

    /** @var int $id_session The ID of the session row in the DB */
    if ( $id_session = $this->get_id_session() ){
      $this->sess_cfg = json_decode($this->db->select_one(
        $this->class_cfg['tables']['sessions'],
        $this->class_cfg['arch']['sessions']['cfg'],
        [$this->class_cfg['arch']['sessions']['id'] => $id_session]
      ), true);
    }
    else{

      /** @var string $salt */
      $salt = self::make_fingerprint();

      /** @var string $fingerprint */
      $fingerprint = self::make_fingerprint();


      /** @var array $p The fields of the sessions table */
      $p =& $this->class_cfg['arch']['sessions'];

      $this->sess_cfg = [
        'fingerprint' => $this->get_print($fingerprint),
        'last_renew' => time()
      ];

      // Inserting the session in the database
      if ( $this->db->insert($this->class_cfg['tables']['sessions'], [
        $p['sess_id'] => $this->session->get_id(),
        $p['ip_address'] => $this->ip_address,
        $p['user_agent'] => $this->user_agent,
        $p['opened'] => 1,
        $p['last_activity'] => date('Y-m-d H:i:s'),
        $p['creation'] => date('Y-m-d H:i:s'),
        $p['cfg'] => json_encode($this->sess_cfg)
      ]) ){
        // Setting the session with its ID
        $id_session = $this->db->last_id();
        $this->session->set([
          'fingerprint' => $fingerprint,
          'tokens' => [],
          'id_session' => $id_session,
          'salt' => $salt
        ], self::$sn);
        $this->save_session();
      }
      else{
        $this->set_error(16);
      }
    }
    return $this;
  }
private function _init_session ( ) { // Getting or creating the session is it doesn't exist yet /** @var user\session */ $ this -> session = user \ session :: get_instance ( ) ; if ( ! $ this -> session ) { $ this -> session = new user \ session ( ) ; } /** @var int $id_session The ID of the session row in the DB */ if ( $ id_session = $ this -> get_id_session ( ) ) { $ this -> sess_cfg = json_decode ( $ this -> db -> select_one ( $ this -> class_cfg [ 'tables' ] [ 'sessions' ] , $ this -> class_cfg [ 'arch' ] [ 'sessions' ] [ 'cfg' ] , [ $ this -> class_cfg [ 'arch' ] [ 'sessions' ] [ 'id' ] => $ id_session ] ) , true ) ; } else { /** @var string $salt */ $ salt = self :: make_fingerprint ( ) ; /** @var string $fingerprint */ $ fingerprint = self :: make_fingerprint ( ) ; /** @var array $p The fields of the sessions table */ $ p = & $ this -> class_cfg [ 'arch' ] [ 'sessions' ] ; $ this -> sess_cfg = [ 'fingerprint' => $ this -> get_print ( $ fingerprint ) , 'last_renew' => time ( ) ] ; // Inserting the session in the database if ( $ this -> db -> insert ( $ this -> class_cfg [ 'tables' ] [ 'sessions' ] , [ $ p [ 'sess_id' ] => $ this -> session -> get_id ( ) , $ p [ 'ip_address' ] => $ this -> ip_address , $ p [ 'user_agent' ] => $ this -> user_agent , $ p [ 'opened' ] => 1 , $ p [ 'last_activity' ] => date ( 'Y-m-d H:i:s' ) , $ p [ 'creation' ] => date ( 'Y-m-d H:i:s' ) , $ p [ 'cfg' ] => json_encode ( $ this -> sess_cfg ) ] ) ) { // Setting the session with its ID $ id_session = $ this -> db -> last_id ( ) ; $ this -> session -> set ( [ 'fingerprint' => $ fingerprint , 'tokens' => [ ] , 'id_session' => $ id_session , 'salt' => $ salt ] , self :: $ sn ) ; $ this -> save_session ( ) ; } else { $ this -> set_error ( 16 ) ; } } return $ this ; }
Sets the user's session for the first time and creates the session's DB row
@return $this
Sets the user s session for the first time and creates the session s DB row