Problem with sessions, stored in files |
I'm having a problem with sessions
I need to store a value in a session so in case user is not logged in. I store this value and after user logs in, I redirect him to the right url etc. I've made a test controller, associated to 2 routes, to try to debug this problem Code: ... Then I do some test in my PC http://localhost/myapp/setcookie/25 and then http://localhost/myapp/getcookie All works fine, but when I do the same test on server https://sub.domain.com/setcookie/25 and then http://sub.domain.com/getcookie The output I get is: userData: Array ( [__ci_last_regenerate] => 1734363353 [_ci_previous_url] => https://sub.domain.com/setcookie/25 ) logged: NULL itemId: The weird thing is that I can see the itemId being stored in the session file (writable/session) on server, after calling setcookie/25 How can I make this work or debug deeper to find out what's wrong ? PS: writable/session has the 777 chmod, and www-data:www-data ownership, etc.
Enrique
https://beza.com.ar
I always initialize my sessions in the initController Method.
PHP Code: <?php What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
I've tried that way
- initializing in BaseController - using the session helper to set and to get data When trying at localhost, it works fine http://localdev/setc/2501515 http://localdev/getc ![]() But when trying on the server, it doesn't https://my.domain.com/setc/2501515 https://my.domain.com/getc ![]() When executed in server the 1st. url to set a cookie (initializing on BaseController, using helper method etc.), https://my.domain.com/setc/2501515 I notice a file were created. When checking the contents of the file writable/session/pref_agrvm9fahkgomh7634id3ks16isfqdq7 Code: __ci_last_regenerate|i:1734521750;prueba_sesion|s:7:"2501515";_ci_previous_url|s:52:"https://my.domain.com/index.php/setc/2501515"; When executing in server the 2nd url to get the cookie/session value, https://my.domain.com/getc another file got created in writable/session. When checking the contents of this newer file writable/session/pref_mfuqd55vf0fnm4ohhk95ng4bc5k0ap34 Code: __ci_last_regenerate|i:1734521751;_ci_previous_url|s:44:"https://my.domain.com/index.php/getc"; I cannot understand the following: 1. The first file created, contains the value set for "prueba_sesion", etc. 2. Why I'm getting 2 files written, one when calling the url to set a session value, and other when calling the url to get the value previously set 3. Why the ci_previous_url contains index.php when I'm working without index.php, I've setup .htaccess correctly and the urls work without index.php I'm wondering if the IT infrastructure here may be the cause of this problem, because this server is behind lots of nginx proxies, firewall, etc. Maybe the browser/server cannot sync well with my session, IP or anything? Now, let's suppose this infrastructure is the cause. How could I solve this in some way, or maybe with another session class. Would this be possible? PS: I've tried setting sessions to work with DatabaseHandler, configured mysql, etc. but the problem still persists. I've tried different browsers, Chrome, Firefox and Brave, none of these worked when trying the server urls
Enrique
https://beza.com.ar
It sounds like it may have something to do with the way the server is configured.
Ask your server provider to check on this for you. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(12-18-2024, 10:55 PM)InsiteFX Wrote: It sounds like it may have something to do with the way the server is configured. No way I'll be able to get fixed by that side, nothing will change. I thought it could be a way to override this Thanks
Enrique
https://beza.com.ar |
Welcome Guest, Not a member yet? Register Sign In |