• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
still losing session userdata across a redirect

#1
I have been battling this problem for a few weeks. My poor debugging choices introduced some other problems but I am back to my session problem. I found this post which shows that others have had the same problem. https://stackoverflow.com/questions/1206...odeigniter

I tried all the advice but it still doesn't work. Here is my config file:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'c:\xampp\htdocs\sub_crud\system\libraries\session';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;


I am considering trying either a flash session to move the one userdata variable I need, or else using database instead of files. Anyone have any other ideas?
proof that an old dog can learn new tricks
Reply

#2
So sessions are working but when you use a redirect your session is resetting? Is that correct? If you session is resetting then flash data would be lost too of course.
Reply

#3
Try a trailing '\' on session_save_path.
Reply

#4
(12-01-2017, 06:27 AM)PaulD Wrote: So sessions are working but when you use a redirect your session is resetting? Is that correct? If you session is resetting then flash data would be lost too of course.

Exactly. I can set the session userdata fine. And I can see that it is being written to at least one session file. In a typical test, 3 session files are created. One includes my data

__ci_last_regenerate|i:1512137748;isUserLoggedIn|b:1;userId|s:1:"1";userid|s:24:"cmljaGIyMDFAZ21haWwuY29t";

another one is blank. And the third has just __ci_last_regenerate|i:1512137807;

The problem is after a redirect the $_SESSION is not being repopulated. I tried stopping the code at the fread to see if it was being read properly, but the file locking causes a crash if I do that. 

I see many people posting with the same problem. I do need to be able to tell is the user has already been authenticated and the email of the user. 
proof that an old dog can learn new tricks
Reply

#5
(12-01-2017, 06:59 AM)dave friend Wrote: Try a trailing '\' on session_save_path.

I tried that Dave but that breaks everything.  Is \'  a special escape character? It seems to be the read that is the issue, not the write. Is there anyway to save the two fields I need  in a browser cookie, and then send it back to the server?
proof that an old dog can learn new tricks
Reply

#6
I tried setting my base_url to $config['base_url']='http://localhost/sub_crud/';

but this caused

A PHP Error was encountered

Severity: Warning

Message: mkdir(): Invalid argument

Filename: drivers/Session_files_driver.php

Line Number: 136

Backtrace:

File: C:\xampp\htdocs\sub_crud\application\controllers\users.php
Line: 15
Function: __construct

File: C:\xampp\htdocs\sub_crud\index.php
Line: 316
Function: require_once

An uncaught Exception was encountered

Type: Exception

Message: Session: Configured save path 'c: mpp\htdocs\sub_crud\system\libraries\session' is not a directory, doesn't exist or cannot be created.

Filename: C:\xampp\htdocs\sub_crud\system\libraries\Session\drivers\Session_files_driver.php

Line Number: 138

Backtrace:

File: C:\xampp\htdocs\sub_crud\application\controllers\users.php
Line: 15
Function: __construct

File: C:\xampp\htdocs\sub_crud\index.php
Line: 316
Function: require_once

Why would this be?
proof that an old dog can learn new tricks
Reply

#7
(I've reformatted the quotes to use code tags, please use that in the future)

(12-01-2017, 06:19 AM)richb201 Wrote:
Code:
$config['sess_expiration'] = 7200;
$config['sess_expiration'] = 0;

Just FYI, the second line overwrites the first ... there's no point in having both of them.

(12-01-2017, 06:19 AM)richb201 Wrote:
Code:
$config['sess_save_path'] = 'c:\xampp\htdocs\sub_crud\system\libraries\session';

This looks like the path to the library itself. You're not supposed to use that.

---

Still, neither of these can cause the problem. It can work perfectly well with all the settings you've shown.

(12-01-2017, 07:32 AM)richb201 Wrote:
(12-01-2017, 06:27 AM)PaulD Wrote: So sessions are working but when you use a redirect your session is resetting? Is that correct? If you session is resetting then flash data would be lost too of course.

Exactly. I can set the session userdata fine. And I can see that it is being written to at least one session file. In a typical test, 3 session files are created. One includes my data

Code:
__ci_last_regenerate|i:1512137748;isUserLoggedIn|b:1;userId|s:1:"1";userid|s:24:"cmljaGIyMDFAZ21haWwuY29t";[/fon

another one is blank. And the third has just [code]__ci_last_regenerate|i:1512137807;

The problem is after a redirect the $_SESSION is not being repopulated. I tried stopping the code at the fread to see if it was being read properly, but the file locking causes a crash if I do that.

I see many people posting with the same problem. I do need to be able to tell is the user has already been authenticated and the email of the user.
[/code]


Well, you see many people posting with the same symptom, not necessarily the same problem.

There's 2 general causes for this symptom to appear:

1. Session files (or otherwise server-side records) can't be written. A LOT of people simply don't read the documentation and don't set (properly) sess_save_path. This isn't the case here, though you should change to a better location.
2. Mismatching cookie parameters - what should be the problem here.

A cookie with the 'secure' flag can't be sent over plain HTTP (must be HTTPS).
A cookie set for domain foo.bar won't be sent to foo.baz, naturally.
A cookie set for path /foo won't be sent to /bar, also naturally.

You should also check/show your cookie settings.

(12-01-2017, 07:35 AM)richb201 Wrote:
(12-01-2017, 06:59 AM)dave friend Wrote: Try a trailing '\' on session_save_path.

I tried that Dave but that breaks everything.  Is \'  a special escape character? It seems to be the read that is the issue, not the write. Is there anyway to save the two fields I need  in a browser cookie, and then send it back to the server?

\ is an escape character; you need to escape it ... with itself, so that it is recognized as a literal one: \\
But that won't help. The library will automatically append it when missing.[/code]
Reply

#8
I changed the past for cookies to: $config['sess_save_path'] = 'c:\xampp\htdocs\sub_crud\session_cookies';

>>A cookie with the 'secure' flag can't be sent over plain HTTP (must be HTTPS).
No prob here. I have secure set to false.

>>A cookie set for domain foo.bar won't be sent to foo.baz, naturally.
I have this set to : $config['cookie_domain'] = ''; What should it be set to?

>>A cookie set for path /foo won't be sent to /bar, also naturally.
This is set to $config['cookie_path'] = '/';
>>You should also check/show your cookie settings.

Where is this? Do you mean?


Code:
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
proof that an old dog can learn new tricks
Reply

#9
Try a more "sane" folder to store the session files.

PHP Code:
$config['sess_save_path'] = APPPATH.'cache'

I don't think your cookies are working correctly.

You give up on using my session testing class?
Reply

#10
(12-01-2017, 09:44 AM)dave friend Wrote: Try a more "sane" folder to store the session files.

PHP Code:
$config['sess_save_path'] = APPATH.'cache'

I don't think your cookies are working correctly.

You give up on using my session testing class?

Yeah. I'm going to try that again. I am a little frustrated by the way xdebug is working (or not). I suspect that sometimes it is not running at all and while I am waiting for breakpoints to "hit" it just executes but never stops. I now suspect that perhaps these little changes I am making might have caused xdebug not to run. Do you know of any way to determine that xdebug is executing? 

APPATH is not defined. Where should that be defined and what to? 
proof that an old dog can learn new tricks
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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