• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with session on default page


I have problem with sessions in CodeIgniter. 
When user log in to system I have this code:

$data_login = array(
    'id' => $user->id,
    'name' => $user->name,
    'email' => $user->email,
    'logged_in' => true

In general, everything works but when I don't log out and close the page tab, then I will visit the site again [b]$this->session->userdata('logged_in')[/b] returns NULL. When I enter another subpage, everything returns to normal - recognizes the logged in user.

Where is a problem? 

I'm afraid that's not enough to go on. It can be pretty much anything. But usually it's miss-configured Cookie paths inside Application/Config/Config.

Or you aren't autoloading sessions.

I load session in autoload:
PHP Code:
$autoload['drivers'] = array('session'); 

My sessions config:
PHP Code:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = sys_get_temp_dir();
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE

I noticed that this happened on the new hosting.
Everything works on old hosting.

Nobody knows how to help?

Instead of using sys_get_temp_dir try making a sessions folder at the same level as the system folder. Set the permissions as described in the documentation. It may or may not help but is worth the experiment. You can look for the creation of files there as you test for a working session.

Remember that $config['sess_save_path'] must be a full and absolute path.

When I created new folder and edited config.php nothing changed - problem still exists.
In created folder I see session files so I don't know what is wrong.

I just noticed the following which is wrong.

PHP Code:
$autoload['drivers'] = array('session'); 

It should be "libraries" not "drivers"

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

Sorry for missing that on an earlier read. Blush

@dave friend, thank you for paying attention.
This change unfortunately didn't help - problem occurs all the time.

I probably found the source of problem.

In my .htaccess:
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.***.pl/$1 [R,L]

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]


<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

ErrorDocument 404 /index.php


I change:

RewriteRule ^(.*)$ https://www.***.pl/$1 [R,L]


RewriteRule ^(.*)$ https://***.pl/$1 [R,L]

and I think it's finally fine.

Thank you for help!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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