Welcome Guest, Not a member yet? Register   Sign In
problems with $_SESSION
#1

[eluser]_SC_[/eluser]
Hi all,
I have some troubles with $_SESSION.
In my controller I have :
Code:
$this-> MAdmins-> verifyUser($u,$pw);
if ($_SESSION['userid'] > 0){
redirect('admin/dashboard','refresh');
}
In my module I have:
Code:
function verifyUser($u,$pw){
        ...
        $Q = $this-> db-> get('admins');
        if ($Q-> num_rows() > 0){
            $row = $Q-> row_array();
            $_SESSION['userid'] = $row['id'];
            $_SESSION['username'] = $row['username'];
        }else{
$this-> session-> set_flashdata('error', 'Sorry, your username or password is incorrect!');
        }
    }
But if I I insert the incorrect data, when i return at the controller in the row :
Quote:if ($_SESSION['userid'] > 0) ...
I get an error: Message: Undefined index: userid
How I can fix this?

Another problem is : why i dont get the messange set in flashdata?
how set_flashdata works? When you print the message? Inside the module or into the controller when you use the $_SESSION object?
#2

[eluser]gigas10[/eluser]
Did you declare session_start() in the constructor of your controller class just after the parent::Controller() line?
Code:
function __construct(){
    parent::Controller();
    session_start();
    $this->load->model('my_model');
}
#3

[eluser]_SC_[/eluser]
yes:

function Welcome()
{
parent::Controller();
session_start();
}
#4

[eluser]gigas10[/eluser]
Oh I see the problem, at least how to get rid of the error message:
Code:
if (isset($_SESSION['userid']) && $_SESSION[‘userid’] > 0){
    //do whatever
}

Also to display flash data you do it in the view.

Code:
echo $this->session->flashdata('error');
#5

[eluser]_SC_[/eluser]
oh thank you very much!




Theme © iAndrew 2016 - Forum software by © MyBB