1

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!

5
  • Flash data is only available for the NEXT http request. Are you making another request? If so, are you making only one? Commented Oct 4, 2016 at 19:45
  • Yes, I'm making another request and only one. Commented Oct 4, 2016 at 19:50
  • Are you certain its just one request being made? Commented Oct 4, 2016 at 19:52
  • Yes, I'm having problems with CodeIgniter Session in general. Problem with set_flashdata and set_userdata. Commented Oct 4, 2016 at 19:55
  • Please edit you question with your session config.php stuff Commented Oct 4, 2016 at 20:12

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

Yes, I'm making another request and only one. I'm having problems with CodeIgniter Session in general. Problem with set_flashdata and set_userdata, I didn't forget the encryption_key.
can you share the code so i have a better understanding how you are making requests
See this example: if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember)) { $this->session->set_flashdata('message', $this->ion_auth->messages()); redirect('/', 'refresh'); } else { $this->session->set_flashdata('message', $this->ion_auth->errors()); redirect('auth/login', 'refresh'); }
this should be available i did not understand y this is not working
0

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;

8 Comments

This is not my problem. I know how to print flashdata and check if is set. I'm having problem with codeigniter session in general, problem with set_flashdata and set_userdata.
I have an edit in the answer. I posted there because will be not readable in here. This is a strange issue.
Yes, I already had done this configuration and it didn't work
Ok, great. Do you have in your database a table named ci_session?
I have, but this is not the problem, the codeigniter session works with no database
|
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.