• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problems with $_SESSION

Hi all,
I have some troubles with $_SESSION.
In my controller I have :
$this-> MAdmins-> verifyUser($u,$pw);
if ($_SESSION['userid'] > 0){
In my module I have:
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'];
$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?

Did you declare session_start() in the constructor of your controller class just after the parent::Controller() line?
function __construct(){


function Welcome()

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

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

echo $this->session->flashdata('error');

oh thank you very much!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.