• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
session flashdata not work correctly in codeigniter 2.2

#1
Hi guys!, can you help me?
I have a problem with session flashdata. never the message containing the session is displayed.

I have this routes:
PHP Code:
//index is a subfolder into the controllers folder
//user is a controller
$route['login'            'index/user/showLogin';
$route['do_login'         'index/user/doLogin';
$route['register'         'index/user/showRegister';
$route['do_register'      'index/user/doRegister'

user.php controller:

PHP Code:
public function showRegister()
{
 
  $this->template->set('title''test register');
 
  $this->template->load('template''index/register'$data);
}

public function 
doRegister()
{
 
  $this->form_validation->set_rules('email'     'Email'               'required|trim|max_length[30]|xss_clean|valid_email|is_unique[users.email]|');
 
  $this->form_validation->set_rules('password'  'Password'          'required|trim|min_length[6]|max_length[20]|xss_clean|alpha_dash');
 
  $this->form_validation->set_rules('rrpassword''Re Password'  'required|trim|min_length[6]|max_length[20]|xss_clean|matches[password]|alpha_dash');

 
  if($this->form_validation->run() == FALSE)
 
  {
 
   $this->showRegister();
 
  }
 
  else
 
  {
 
      $email      $this->input->post('email');
 
      $pass       $this->input->post('password');
 
      $password   $this->bcrypt->hash_password($pass);

 
      // check if the password was encrypted
 
      if ($this->bcrypt->check_password($pass$password))
 
      {
 
          $data =array(
 
              'email'     => $email,
 
              'password'  => $password,
 
          );

 
          $insert $this->user_model->register($data);

 
          if(!$insert)
 
          {
 
              echo 'error';
 
          }
 
          $this->session->set_flashdata('info''registered');
 
          redirect('login''refresh');
 
      }
 
      else
 
      {
 
          $this->session->set_flashdata('info''Oops.. error...');
 
          redirect(base_url('login'), 'refresh');
 
      }
 
   }
 
 

to display messages I do this in the view "login":

PHP Code:
<div class="alert alert-info alert-dismissible" role="alert">
 
  <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
 
  Test: <?php echo $this->session->flashdata('info'); ?>
</div> 

But never the message is printed. i Tried this:

PHP Code:
$this->session->set_flashdata('info''test......');
$this->session->keep_flashdata('info');
redirect('login''refresh'); 

But not works. Also add the favicon.ico to the root folder, but does not work. I'm trying to fix it a few hours ago. It may be the version of PHP?
Also i tried this:

PHP Code:
$this->session->sess_create();
$this->session->set_flashdata('info''test......');
redirect('login''refresh'); 
Reply

#2
Can you change the name of the subfolder "index" in the controllers Folder to another name to something else like "member" and try again?

I think CI is having problem interpreting the URL since it contains the "index" keyword
Reply

#3
Hi ohiageorge, thanks for your reply.
i changed name of subfolder "index" to "test" but not works. I tested everything and still not working. Can you think of anything else?
Reply

#4
What are your session settings?

Reply

#5
Hi Rufnex, thanks for your reply.
you want to say? I cannot understand
Reply

#6
In your /application/config/config.php there is a section "Session Variables". i want to check if there is all well done there.
Btw .. do you load the session library?

PHP Code:
$this->load->library('session'); // or in your autoload.php 

What you do seams absolutly right. You can also try a simple test

PHP Code:
$this->session->set_flashdata('item''value');
echo 
$this->session->flashdata('item');
print_r($this->session->flashdata()); 

Load this 2 or more times any you should see a filled array.

Reply

#7
Hello again,
I load library this way:

autoload.php
PHP Code:
$autoload['libraries'] = array('form_validation','input','session','template','database','breadcrumbs'); 

Also i try loading the library on the builder, but not working. In my config.php file on Session Variables i have this:

PHP Code:
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| If you use the Encryption class or the Session class you
| MUST set an encryption key.  See the user guide for info.
|
*/
$config['encryption_key'] = '#[email protected]$';

/*
|--------------------------------------------------------------------------
| Session Variables
|--------------------------------------------------------------------------
|
| 'sess_cookie_name'        = the name you want for the cookie
| 'sess_expiration'            = the number of SECONDS you want the session to last.
|   by default sessions last 7200 seconds (two hours).  Set to zero for no expiration.
| 'sess_expire_on_close'    = Whether to cause the session to expire automatically
|   when the browser window is closed
| 'sess_encrypt_cookie'        = Whether to encrypt the cookie
| 'sess_use_database'        = Whether to save the session data to a database
| 'sess_table_name'            = The name of the session database table
| 'sess_match_ip'            = Whether to match the user's IP address when reading the session data
| 'sess_match_useragent'    = Whether to match the User Agent when reading the session data
| 'sess_time_to_update'        = how many seconds between CI refreshing Session Information
|
*/
$config['sess_cookie_name']        = 'ci_session';
$config['sess_expiration']        = 7200;
$config['sess_expire_on_close']    = TRUE;
$config['sess_encrypt_cookie']    = TRUE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']        = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']    = 300

I Added the code you told me and I get this error:
Quote:A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for CI_Session::flashdata(), called in C:\xampp\htdocs\projects\application\controllers\test\user.php on line 81 and defined

Filename: libraries/Session.php

Line Number: 578
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: key

Filename: libraries/Session.php

Line Number: 580


the "$key" variable refers to the constant encryption_key?.
when i add this code:
PHP Code:
$this->session->set_flashdata('item''value');
echo 
$this->session->flashdata('item');
print_r($this->session->flashdata('item')); 

this not print anything on screen.
Again thank you for your response
Reply

#8
Ups i think in CI 2 you must give flashdata() the property name as parameter. Have you also checked your cookie setting in the config.php?

Reply

#9
Btw, have you installed (our new friend) mycrpyt on your server (phpinfo() will tell you about). In CI 2 you will need it.

Reply

#10
Hi Rufnex,
downloaded again CI and created a separate project. and working correctly. apparently i configured incorrectly config.php file. I never thought I was going to be that. I apologize for stealing so long. Thank you very much.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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