Welcome Guest, Not a member yet? Register   Sign In
Saving session on database get session id
#1

HI , how can i get the id of ci_sessions table of the user logged (to save in users table )  ? this is my session data:

Code:
__ci_last_regenerate|i:1690527426;admin_id|s:1:"2";admin_email|s:25:"[email protected]";is_admin|i:1;is_super_admin|s:1:"1";_ci_previous_url|s:76:"http://riepilogo_locale/index.php/admin_Dipendenti/lista_completa_dipendenti";
Reply
#2

What do you want to do?
Reply
#3

(This post was last modified: 07-28-2023, 07:06 AM by pippuccio76.)

(07-28-2023, 01:38 AM)kenjis Wrote: What do you want to do?

I want allow the access only one user at time
Reply
#4

(This post was last modified: 07-28-2023, 07:10 AM by ozornick.)

session()->get('your_session_key'); return current session data
or use query builder as:
PHP Code:
$db->table('ci_session')->where('id'$session_id)->get() 
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#5

(07-28-2023, 07:09 AM)ozornick Wrote: session()->get('your_session_key'); return current session data
or use query builder as:
PHP Code:
$db->table('ci_session')->where('id'$session_id)->get() 

I want know $session_id......
Reply
#6

sessions are not designed for this. In what situation do I need to make requests?
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#7

I must add a field in users tablet ( id_ci_sessions) and save the id of ci_sessions tablet when user login . If the session are bot expired( time x for esample 60 Min) another user cannot login...
Reply
#8

This is not how they do it. Add the `token` or `logged_in` field to the user table. In the session, store this label (code, hash) Create a filter with a label check in the session and delete it if the session is lost. Now, if a new user logs in, the token will change and other sessions will become invalid. This is the general logic, you have to adapt for yourself
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#9

You could create a logged_in database table and store the users_id in it, then with each log in check it
for the user_id to see if thery are already logged_in.

Something like this.

Code:
-- --------------------------------------------------------

--
-- Table structure for table `logged_in`
--

DROP TABLE IF EXISTS `logged_in`;
CREATE TABLE IF NOT EXISTS `logged_in` (
  `id`        INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id`    INT(11) UNSIGNED NOT NULL,
  `created_at` DATETIME            NULL DEFAULT NULL,
  `updated_at` DATETIME            NULL DEFAULT NULL,
  `deleted_at` DATETIME            NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = `utf8mb4` COLLATE = `utf8mb4_unicode_ci`;

--
-- Dumping data for table `logged_in`
--

You would need to check this table each time when a user logs into the system before logging them in.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#10

See https://forum.codeigniter.com/showthread...#pid410471
Reply




Theme © iAndrew 2016 - Forum software by © MyBB