1
votes

I loaded the session class in autoload.php, but when I use the CodeIgniter session nothing happens.

Example: I set flash data:

$this->session->set_flashdata('message', 'HELP!');

When I print this information nothing happens!

Example:

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

What is the problem with my code?

NOTE: I'm having problems with CodeIgniter Session in general, problem with set_flashdata and set_userdata.

UPDATE:

It was a server problem, now it's solved. Thanks for all!

3
Flash data is only available for the NEXT http request. Are you making another request? If so, are you making only one? - Kisaragi
Yes, I'm making another request and only one. - Matheus Marzochi
Are you certain its just one request being made? - Kisaragi
Yes, I'm having problems with CodeIgniter Session in general. Problem with set_flashdata and set_userdata. - Matheus Marzochi
Please edit you question with your session config.php stuff - Mr. ED

3 Answers

2
votes

flash data is only available to you for the next server request within that specific session . means if you made another request or put a redirect after loading a view then the flash message will not appear . and other then this dont forget to add a encryption_key key in config file auto loading session library and not try to redirect to another page after loading a view . hope this will answer your question

0
votes

Nothing happen because this:

$this->session->set_flashdata('message', 'HELP!');

Is just setting 'HELP' in the session 'message';

$this->session->set_flashdata('error', 'WOOPS!');

You need to set also some conditions in your view in order to read the session and see the result:

<?php
    if($this->session->flashdata('message'))
    {
        ?>
          <div class="container" style="padding-top:80px;">
            <div class="alert alert-info alert-dismissible" role="alert">
              <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <?php echo $this->session->flashdata('message');?>
            </div>
          </div>
        <?php
    }elseif($this->session->flashdata('error')){
      ?>
          <div class="container" style="padding-top:80px;">
            <div class="alert alert-warning alert-dismissible" role="alert">
              <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <?php echo $this->session->flashdata('error');?>
            </div>
          </div>
        <?php
    }
?>

As you can see there are here two examples one for the message (success) and one for the error (fail)

EDIT:

As a reaction of your comment I post this here because in the comment wont be readable:

As you say you have already done this:

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

Do you also have set this in the config?

 $config['encryption_key'] = 'DCF564RT9JN761AZX56FR76Rd8hg6s12';

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_session';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
0
votes

Download the latest version Codeigniter (Version 3.1.6) from Codeigniter official website and replace the system folder to your Codeigniter project and it will works.