Welcome Guest, Not a member yet? Register   Sign In
Login and restricted page CI3 ?
#1

Hi guys?
I decided to update the CI 2 to version 3. The problem is in a login system with restricted area that does not work in version 3. How do I become functional in version 3? Below the settings and code:

/autoload.php
$autoload['libraries'] = array('database','session');

/config.php
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = NULL;
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

/database.php
configuração ok

/add ci_sessions table:
CREATE TABLE IF NOT EXISTS `ci_sessions` (
       `id` varchar(40) NOT NULL,
       `ip_address` varchar(45) NOT NULL,
       `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
       `data` blob NOT NULL,
       PRIMARY KEY (id),
       KEY `ci_sessions_timestamp` (`timestamp`)
);
ok setting

/open session (File_model.php):
$this->db->where('email',$email);
$this->db->where('safe',$safe);
$this->db->where('active',1);
$ws_accadd = $this->db->get('user')->result();
if (count($ws_accadd)===1) {
$dados = array('email' => $ws_accadd[0]->email, 'logado' => TRUE);
$this->session->set_userdata($dados);

/page restricted Contoller (file.php):
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Runcode extends CI_Controller {
   
public function __construct() {
parent::__construct();
if (!$this->session->userdata('id') || !$this->session->userdata('logado')) {
redirect('appaccount/usercon');
}
}

/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index() {
        // msg screen
$this->load->view('welcome_message');
}
}
Reply
#2

Replace
PHP Code:
if (!$this->session->userdata('id') || !$this->session->userdata('logado')) {
   redirect('appaccount/usercon');

by:
PHP Code:
if (!$this->session->has_userdata('id') || !$this->session->has_userdata('logado')) {
   redirect('appaccount/usercon');

Reply
#3

I made the changes and I can not log me. follows the error:

http://workspace.webstrucs.com/appaccount/userdas
Reply




Theme © iAndrew 2016 - Forum software by © MyBB