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

#11
I did not put enough P's in APPPATH. (Earlier reply has been corrected.) It's defined in index.php
Reply

#12
Thanks. That took care of it. Funny how one mispelled thing can totally eff up you code. IDE's in the past (ie PWB) wouldn't let that happen.
proof that an old dog can learn new tricks
Reply

#13
(12-01-2017, 08:49 AM)richb201 Wrote: 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;

Yes, that is what I meant.

cookie_domain should be set to your website's domain ... I just now notice that you're working on localhost - that can cause problems with cookies, try emulating an actual hostname.

(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'] = APPPATH.'cache'

I don't think your cookies are working correctly.

You give up on using my session testing class?

Session files are not cache, don't recommend this.
A directory prepared specifically for session files is the most sane thing.
Reply

#14
I don't think anyone else has mentioned it, but I've learned that there can be problems with the order that you set session data and do the redirect. I always set the redirect before writing to the session. I've had problems changing that order in the past.
Reply

#15
This is how I setup my file sessions, there may be a better way but it works for me.

Create a new directory named writable in the root along with the ./application and ./system directories.

This is the config.php settings:

PHP Code:
// Session settings.
$config['sess_driver'            'files';
$config['sess_cookie_name'       'ci_session';
$config['sess_expiration'        7200;
$config['sess_save_path'         APPPATH.'../writable' //NULL;
$config['sess_match_ip'          FALSE;
$config['sess_time_to_update'    300;
$config['sess_regenerate_destroy'] = FALSE;

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

Works just fine for me and makes it easy to delete the session files when needed.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#16
(12-02-2017, 01:42 PM)skunkbad Wrote: I don't think anyone else has mentioned it, but I've learned that there can be problems with the order that you set session data and do the redirect. I always set the redirect before writing to the session. I've had problems changing that order in the 
I don't really understand. But ill try it.
proof that an old dog can learn new tricks
Reply

#17
(12-03-2017, 05:59 AM)richb201 Wrote:
(12-02-2017, 01:42 PM)skunkbad Wrote: I don't think anyone else has mentioned it, but I've learned that there can be problems with the order that you set session data and do the redirect. I always set the redirect before writing to the session. I've had problems changing that order in the 
I don't really understand. But ill try it.

I don't really understand the reason either, but it has made a difference for me when doing redirects and dealing with sessions.
Reply

#18
Skunk, I tried it out and it worked! Then I removed it back to the old order, and it seems it still worked. So I am not sure what made that happen. I did recently follow Dave instructs on moving the base_url which might be the reason it now works. I am using phstorm and debugging with xdebug. The debugging has stop working. It seems to be stopping at breakpoints but when I try using phpstorm to find the spot, there is no breakpoint there. Very frustrating because as I like to say, I couldn't code 10 lines w/o a debugger. Any who I am am just glad to be unstuck.
proof that an old dog can learn new tricks
Reply

#19
(12-03-2017, 04:27 AM)InsiteFX Wrote:
PHP Code:
$config['sess_save_path'         APPPATH.'../writable' //NULL; 

It's supposed to be secure, not just writable.

This is the entire reason why it is up to you to set it up properly, otherwise the framework can easily find the OS tmp path and use it - that's not the point.
Reply

#20
(12-03-2017, 11:27 AM)skunkbad Wrote:
(12-03-2017, 05:59 AM)richb201 Wrote:
(12-02-2017, 01:42 PM)skunkbad Wrote: I don't think anyone else has mentioned it, but I've learned that there can be problems with the order that you set session data and do the redirect. I always set the redirect before writing to the session. I've had problems changing that order in the 
I don't really understand. But ill try it.

I don't really understand the reason either, but it has made a difference for me when doing redirects and dealing with sessions.

Can you elaborate and/or show examples of this where it does/doesn't work?
It's not something that should make a difference. If anything, doing a redirect before altering session vars could discard those changes to the session.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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