ivantcholakov / starter-public-edition-4

A PHP application starter, based on CodeIgniter 3
MIT License
164 stars 89 forks source link

Database Session #38

Closed Exelord closed 9 years ago

Exelord commented 9 years ago

Hi, I noticed that Databese Session driver isn't working correctly. When its enabled, every time when i refresh a main page I've got an error something like "Repeated ID blah blah blah". So looked to the code and i think there is a problem with validation varible _row_exists. Could you look at this? I really need help with database session.

Btw. I love your project :) every time when I build some app i use your masterpiece. Thank you and keep going.

ivantcholakov commented 9 years ago

Are you sure that the table schema is updated in your project?

CREATE TABLE `ci_sessions` (
  `id` varchar(40) NOT NULL,
  `ip_address` varchar(45) NOT NULL,
  `timestamp` int(11) NOT NULL,
  `data` blob NOT NULL,
  PRIMARY KEY (`id`),
  KEY `ip_address` (`ip_address`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

https://github.com/bcit-ci/CodeIgniter/issues/3073#issuecomment-44755806

Exelord commented 9 years ago

Yep, its exactly the same. The first session writing is working very well, and when i deleted this piece of code 171-180 Session_database_driver.php its working too but its important fragment.

ivantcholakov commented 9 years ago

Ok, I am working on a real application and I will switch it into the database driver for seeking problems.

ivantcholakov commented 9 years ago

I turned on the database driver with these settings:

$config['sess_driver'] = 'database';
$config['sess_save_path'] = 'ci_sessions';

It works, I don't see an error so far.

Exelord commented 9 years ago

Thats my configuration:

$config['sess_driver']          = 'database';
$config['sess_cookie_name']     = 'ac584bae';
$config['sess_expiration']      = 4 * 60 * 60;  // 4 hours
$config['sess_save_path']       = 'ci_sessions';
$config['sess_match_ip']        = TRUE;
$config['sess_time_to_update']  = 300;

$config['cookie_prefix']    = '';
$config['cookie_domain']    = (IS_CLI || $_SERVER['SERVER_NAME'] == 'localhost') ? '' : $_SERVER['SERVER_NAME'];
$config['cookie_path']      = $DETECT_URL['base_uri'];
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;

and its stil not working :/ for sure i will install second copy of your project on my server and i will check it.

ivantcholakov commented 9 years ago

Try a clean install of my project and test this http://iridadesign.com/starter-public-edition-4/www/playground/captcha

It uses the session.

If the problem persists, install a clean CodeIgniter, download it from 'feature/session' branch, it contains the new Session library I use. Write simple test code in the home page.

Exelord commented 9 years ago

Another error after clean install of your project. I checked on 3 database- 2 remote and local.

Error Number: HY000/1

no such table: ci_sessions

SELECT "data" FROM "ci_sessions" WHERE "id" = 'b05f96e1985be82468279e896d083c628fb03384'

Filename: libraries/Session/drivers/Session_database_driver.php

Line Number: 138

In each database is exist the table.

The branch 'feature/session' works very well.

ivantcholakov commented 9 years ago

platform/common/config/database.php - Did you set connection data there?

platform/common/config/database.php - Did you autoload the database?

$autoload['libraries'] = array(
    'database',
    'session',
    'events',
);
Exelord commented 9 years ago

Of course i do. The same settings are in clean CI and it works.

ivantcholakov commented 9 years ago

Yes, I've just seen the error 'no such table: ci_sessions'. I will see why is that.

ivantcholakov commented 9 years ago

Still seeking, for now I've reported issue 3473 to CodeIgniter.

Exelord commented 9 years ago

So, could you propose me other safe method for storing session in CI? I need to how fast i can start the application but i need safe session, because its a e-shop.

Thanks for all :)

ivantcholakov commented 9 years ago

Ah yes, I found it. In the site_example application I connect to a demo database.

Rename the file platform/applications/site_example/config/database.php into _database.php

An then see whether it works. Some of the demos would get broken, but this is expected, you will remove them anyway.

I use for my developments the 'files' driver for months, I don't see problems with it. But anyway, check the database driver in your server, it is good to know that alternative works, just in case.

Exelord commented 9 years ago

Ok, that`s was the problem. But my previously problem was other. fortunately i found solution. I had to create database.php in config of my application not edit in common folder and now sessions seem to be works correctly. I will test it tonight.

But i have another... too with session. Maybe this is correct but i have to ask you. When I write var_dump() command the sessions shout:

A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /blah/blah/blah/public_html/platform/applications/shop/modules/offline/controllers/Offline_controller.php:14)
Filename: Session/Session_driver.php
Line Number: 102

A PHP Error was encountered
Severity: Warning
Message: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent
Filename: Session/Session.php
Line Number: 638
ivantcholakov commented 9 years ago

It is normal var_dump() to cause these warning before session has been initialized. Don't pay attention on these.

When the issue CI 3473 gets closed I will upgrade immediately with a special release candidate only on this. So, let this issue stay open as a reminder until then.

Exelord commented 9 years ago

Ok, thanks,

I was wrong. Problem with session does not go away :/

Error Number: 1062
Repetition '37e41ffa8b017ed3c7080cebfa3ec4cc5e6c250e' for key 'PRIMARY'
INSERT INTO `mys_ci_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('37e41ffa8b017ed3c7080cebfa3ec4cc5e6c250e', '83.27.60.187', 1421165160, '')
Filename: libraries/Session/drivers/Session_database_driver.php
Line Number: 173
ivantcholakov commented 9 years ago

Hm... this should not be allowed to happen at all. I'll wait to see how code would change. Meanwhile use the 'files' driver.

ivantcholakov commented 9 years ago

@Exelord

I've made a release v4.0.0-rc60 after CI 3473 has been closed. The database driver works for me, I hope it to be OK in your place too.

After the change this is what narfbg wrote "You better don't use a database other than PostgreSQL and MySQL for storing session data, as it won't have locks."

I don't know which of the two drivers is "better", maybe this would be clarified within CI documentation. I used to use the 'files' driver.

Exelord commented 9 years ago

OK, thanks for all :) So I will test it tomorrow and if database session wont wokrs i will try use yours method :)

Btw. Did you know fast method to update your project on my server without changing necessary files where i made changes?

ivantcholakov commented 9 years ago

No, I don't know automatic way, I use FTP and I can see what GIT-controlled files/directories has changed and I update only them.

I did not expect that I would have to make so many release candidates. When CI3 is out I would make a stable release and after that the project will not change so fast.

Exelord commented 9 years ago

Ok, so i think you can close the issue now.

Did you think about add a Polish translation or write a documentation of your project?

ivantcholakov commented 9 years ago

Ok, I'll add the Polish translation. The README file will be extended before the stable release.

ivantcholakov commented 9 years ago

@Exelord

For database driver: I think, when the front-end and back-end have different session id (totally independent sessions), then the database tables for session support should be two with different names. Just crossed my mind.

Exelord commented 9 years ago

Hmm, maybe thats the correct way. Anyway, when I updated to latests changes database_driver it was terrible. Tons of error. And i decide to use Redis session. Maybe when CI3 will be official release the database session will be usable. But fortunately I noticed increased speed of loading sessions. So Im happily Redis user :)

Btw. I have 3 other application but on the old version of your project and there database session works fine. Admin app and the site app use one DB and ci_sessions table. Its crazy :)

Could I write to you email? I found something weird but i wont create unnecessarily a new issue.

ivantcholakov commented 9 years ago

Yes.