Welcome Guest, Not a member yet? Register   Sign In
[Solved] Session issue : Can't keep it persistent
#1

(This post was last modified: 12-22-2016, 01:19 AM by Jurden.)

Hello,

I don't know why but I lose my session at any refresh.
I try to store it by file and now in my database.

Here it's the only thing I have when i refresh my page (anytime different) :
PHP Code:
Array
(
 
   [__ci_last_regenerate] => 1481814234


This is my current config :

AUTOLOAD
PHP Code:
$autoload['libraries'] = array( 'database''session' ); 

CONFIG
PHP Code:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_sessions';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 30000;
$config['sess_regenerate_destroy'] = TRUE;

$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';


$config['global_xss_filtering'] = TRUE

MODEL
PHP Code:
public function createSession(){
 
       if( !isset( $this->session->watch_dog ) ){
 
           $this->session->set_userdata'watch_dog'0);
 
       }
 
       ifget_cookie('watch_dog') == null ){
 
           set_cookie('watch_dog'0,'130000');
 
       }
 
   }

 
   public function addConnectionCounterAttempt(){
 
       $this->createSession();
 
       // SESSION
 
       $new_value $this->session->userdata['watch_dog'] + 1;
 
       $this->session->set_userdata'watch_dog'$new_value );
 
       // COOKIE
 
       set_cookie'watch_dog'$new_value'3600' );
 
   

If you have any ideas...
Thank you.
Reply
#2

sess_save_path has to be the name of your sessions table if you're using the database driver.
Reply
#3

I changed the path but still the same.
I try to use native sessions instead and same result.
Reply
#4

(This post was last modified: 12-16-2016, 09:23 AM by skunkbad.)

Another thing is that null ever will be == null. Instead you would use:


PHP Code:
if( is_nullget_cookie('watch_dog') ) ) 
OR you could probably just do:
PHP Code:
if( get_cookie('watch_dog') ) 
Reply
#5

Well noticed.
I'll keep looking on that issue.
Reply
#6

I finaly found the solution.
I just reset my cookies configuration and it work again.
Reply
#7

I have a problem like this.

Everytime when i refresh the page, it creates a new session. What should i do?

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'pbsession';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'pbsession';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;

----

$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;

I use PHP 7.1.2, IIS 7 and Codeigniter 3.1 on Windows Server 2008 R2.
Reply
#8

(12-22-2016, 01:19 AM)Jurden Wrote: I finaly found the solution.
I just reset my cookies configuration and it work again.

What does that mean? How do you reset this? It would be nice if you could elaborate on this a bit more.
Reply
#9

He put the cookie configuration back to it's default in the config.php file.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#10

Correct Wink
Reply




Theme © iAndrew 2016 - Forum software by © MyBB