Welcome Guest, Not a member yet? Register   Sign In
Problem with session on default page
#1

Hi,

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

Code:
$data_login = array(
    'id' => $user->id,
    'name' => $user->name,
    'email' => $user->email,
    'logged_in' => true
);
$this->session->set_userdata($data_login);

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? 
Reply
#2

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.
Reply
#3

(This post was last modified: 09-25-2019, 01:21 AM by mazz.)

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

@edit:
I noticed that this happened on the new hosting.
Everything works on old hosting.
Reply
#4

Nobody knows how to help?
Reply
#5

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.
Reply
#6

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.
Reply
#7

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
Reply
#8

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

I probably found the source of problem.

In my .htaccess:
Code:
<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>

<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

</IfModule>


I change:

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

to:

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

and I think it's finally fine.

Thank you for help!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB