CodeIgniter Forums
how to get logged_in session status in native php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: how to get logged_in session status in native php (/showthread.php?tid=76746)



how to get logged_in session status in native php - starchild - 06-15-2020

We have a mix of CI-3 and plain PHP, and want to be able to identify if a user is logged in via CI, so that we can display certain content.

Is there a way to do this?

Thank you.


RE: how to get logged_in session status in native php - neuron - 06-15-2020

Hi,

This is the code I used in some of my project:

update your CI index.php:

PHP Code:
//$system_path = 'system';
$system_path dirname(__FILE__) . DIRECTORY_SEPARATOR 'system';
//$application_folder = 'application';
$application_folder dirname(__FILE__) . DIRECTORY_SEPARATOR 'application'


In your non CI PHP code
Code:
//relative path to CI index.php
include('../../../index.php');
ob_end_clean();
$CI =& get_instance();
$CI->load->driver('session');

//this this index I set with $this->session->set_userdata()
if(@$_SESSION['logged_in'] != TRUE){
    redirect(BASE_URL);
}



RE: how to get logged_in session status in native php - php_rocs - 06-15-2020

@starchild,

There are many ways to track that information. I'll give you another example. I track when users log into my app. I put the date, time, userid and activity id(001 - Log In, 002 - Log Out, etc) into a audit table that tracks user app usage. I'm then able to pull which users are logged into the app and I have information for future statistical purposes as well.