-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: session DatabaseHandler does not set timestamp
column properly
#4935
Comments
Pretty sure this is a duplicate of #4807 and already fixed. Try the latest version of the |
I've tried both origin/4.2 and the HEAD/develop branch and they both do not correctly update the timestamp column for the recommended database definition in the documentation for the session table: CREATE TABLE IF NOT EXISTS `ci_sessions` (
`id` varchar(128) NOT NULL,
`ip_address` varchar(45) NOT NULL,
`timestamp` timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
`data` blob NOT NULL,
KEY `ci_sessions_timestamp` (`timestamp`)
); Updating the database to try and update to CURRENT_TIMESTAMP also does not work: CREATE TABLE IF NOT EXISTS `ci_sessions` (
`id` varchar(128) NOT NULL,
`ip_address` varchar(45) NOT NULL,
`timestamp` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`data` blob NOT NULL,
KEY `ci_sessions_timestamp` (`timestamp`)
); Unless I'm missing something, I'm pretty sure I pointed out the problem in my OP: the assignment of |
@MGatner it looks like @michalsn made an attempt to repair the problem but his change isn't in the HEAD branch UPDATE: michal's change doesn't appear to be in the develop branch, but I was able to download a ZIP from the 4.2 branch via the browser UI which appears to work. I'm wondering about a couple of things:
|
Glad you figured it out! I'm not sure what happened with your clone but it should definitely be in place on Our next release will be a content-free restyle of the code to PSR-12 (plus some others) guidelines. Because of this we have been directing all content changes to |
This bug/issue is definitely a duplicate, so I'm going to close it, but shouldn't that change be applied to the develop branch also? It's a pretty fundamental bug if everybody's session gets wiped every time sessions are garbage collected. |
@sneakyimp Did you read my previous response? TL;DR: No changes to |
I did, and did not realize from reading it that no changes are being made to Clearly, I am of the opinion that this fix should be deployed ASAP. That said, I'm closing this issue. |
Sorry to be unclear. After If something merited a hotfix, under Git Flow this would be applied to |
Describe the bug
The file system/Session/Handlers/DatabaseHandler.php fails to insert or update correct timestamp values the
timestamp
column.CodeIgniter 4 version
4.1.3
Affected module(s)
system/Session/Handlers/DatabaseHandler.php
Expected behavior, and steps to reproduce if appropriate
When you configure your CodeIgniter installation to use the DatabaseHandler for sessions, and you define the
ci_sessions
database table as described here, then the records insert into the ci_sessions table should be created withtimestamp
column containing the current timestamp. As you access the site, these records should have the timestamp column properly updated.This problem is clearly due to the means by which the query is generated. The code attempts this:
or this:
When these arrays are handed to the builder->update() or db->table->insert() methods, the scalar string
'now()'
gets escaped, which yields a query like so:MySQL ends up setting the timestamp to '0000-00-00 00:00:00', which is clearly incorrect.
This could be remedied by generating a datetime string from PHP's settings like so:
however this might result in a timestamp that doesn't match the current time on the SQL server (sometimes SQL server time doesn't match PHP server time). OR -- and I don't know for sure -- this might yield a value that doesn't match with the timezone specified in CodeIgniter's config.
Alternatively, the SQL could be manually generated. Or perhaps we could add a parameter or property to the objects in use to prevent the values from being escaped.
Context
The text was updated successfully, but these errors were encountered: