Reputation: 1481
I need to create an admin feature that will allow an admin to destroy a user's session and redirect them to a new page in real time.
For example:
I know how to remove Bob's session and force him to log back in when he goes to view a new page. But I do not know how to forcibly redirect Bob in real time. I'm guessing I need some kind of an active connection with Bob via Javascript so that I can push the command.
How would I do that? The only real-time Javascript knowledge I have is with AJAX, and that's usually triggered from the client-side and not the server-side.
I am using PHP 7.3 and CodeIgniter4 on the back-end. Currently no libraries on the front-end.
Upvotes: 1
Views: 56
Reputation: 5322
You can use codeigniter 4 events. EVENTS
use CodeIgniter\Events\Events;
From admin side you can trigger some events
\CodeIgniter\Events\Events::trigger('some_events', $foo, $bar, $baz);
and on user side you can use on to get that event
Events::on('some_event', function($foo, $bar, $baz) {
...
});
Note : codeigniter 4 is not ready for production yet.
Upvotes: 1