CodeIgniter Forums
Database and session library ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Database and session library ? (/showthread.php?tid=74119)



Database and session library ? - Digital_Wolf - 07-24-2019

Hello all !

I'm trying to make an authorization system and I would like to combine in my database the table that the session library uses and the one that I created for the rest of the user information.

The fact is that my table also uses "time() functions that generate exactly the same timestamp as when creating sessions, but the documentation says that I should use such fields as "ip_address", "id" and so on...


Q: Where can I change these field names to avoid future errors ?


RE: Database and session library ? - Digital_Wolf - 07-24-2019

(07-24-2019, 10:00 AM)Digital_Wolf Wrote: Hello all !

I'm trying to make an authorization system and I would like to combine in my database the table that the session library uses and the one that I created for the rest of the user information.

The fact is that my table also uses "time() functions that generate exactly the same timestamp as when creating sessions, but the documentation says that I should use such fields as "ip_address", "id" and so on...


Q: Where can I change these field names to avoid future errors ?

I found all this data in the file "System\Session\DatabaseHandler.php"
and I want to be sure that these are exactly all the values that the session library uses,
also I want to make sure that it gets into every field of the database:

1)
Code:
`id` varchar(128)
- this session id is exactly the same if it was recorded in the file name, using $sessionDriver = ***FileHandler.

2)
Code:
`ip_address` varchar(45)
- Well, it is clear that the user's ip.

3)
Code:
`timestamp` int(10)
- I assume this is the timestamp when was the session created.

4)
Code:
`data` blob
- ??? when was the last time there was a "regeneration" session ???

P.S.: Correct me if I'm wrong about something !


RE: Database and session library ? - InsiteFX - 07-25-2019

It's all right there in the CodeIgniter 4 User's Guide.

Database Sessions


RE: Database and session library ? - Digital_Wolf - 07-25-2019

(07-25-2019, 04:25 AM)InsiteFX Wrote: It's all right there in the CodeIgniter 4 User's Guide.

Database Sessions

Yes, I know that everything is in order,
but I would like to know how(or where) I can change the names of the fields that used in this library ?


CREATE TABLE IF NOT EXISTS `ci_sessions` (
       `id` varchar(128) NOT NULL,
       `ip_address` varchar(45) NOT NULL,
       `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
       `data` blob NOT NULL,
       KEY `ci_sessions_timestamp` (`timestamp`)
);


For example, I want to have the name "users_ip" instead of "ip_address", and the place "id" I want to be "users_id"...


RE: Database and session library ? - kilishan - 07-25-2019

Those changes are not possible without overriding the library and making your own modifications to it.

Can I ask why you want to make those changes? Changing 'id' to 'users_id' doesn't make sense. It's not saving a user ID there, it's the session ID defined by PHP.


RE: Database and session library ? - Digital_Wolf - 07-26-2019

(07-25-2019, 02:00 PM)kilishan Wrote: Those changes are not possible without overriding the library and making your own modifications to it.

Can I ask why you want to make those changes? Changing 'id' to 'users_id' doesn't make sense. It's not saving a user ID there, it's the session ID defined by PHP.

I realized that I can't just change it  Sad 
But I would like to have such fields in just one table:
1) Users_id - The serial number of the user.
2) Sessions_id - Individual session number of the users, but you have this field is referred to as "id"
3) Signup_ip - To track the ip of the user under which he sent the registration form.
4) Signin_ip - To track the ip of the user under which he sent the authentication form.
and a few more fields for login, password, 2FA secret code and so on.

P.S. I would be very grateful if you could help me change the names of the fields, I just love when clean and order.  Angel


RE: Database and session library ? - kilishan - 07-26-2019

Don't change the sessions table for that. Make a new table for users where you can store anything you want.


RE: Database and session library ? - Digital_Wolf - 07-26-2019

(07-26-2019, 06:22 AM)kilishan Wrote: Don't change the sessions table for that. Make a new table for users where you can store anything you want.

Oh well, then I will not have any optimization with this table, I will have to use the same functions twice and enter their data in the table.

Well I'll put up with it, thank you very much for the answers !


RE: Database and session library ? - Navindex - 10-30-2019

I'm having the same issue. My database simply has different naming conventions. It would be nice to have more flexibility: for example a simple configuration setting where we could use our own Model.