Reputation: 922
I am attempting to capture exiting sessions from a NONE codeigniter site, the site has a variable called $_SESSION['username']
, now when the current user is logged from that site and attempt to visit the codeigniter site the controller will just transfer the current $_SESSION
to set_userdata
, so far below is my code but i have no luck trying to print_r
if its successfully captured, any help would be great!
I am using the $this->session->set_userdata
.
<?php
class Pages extends CI_Controller{
public function view($page = 'home'){
if(!file_exists(APPPATH.'views/pages/'.$page.'.php')){
show_404();
}
$this->session->set_userdata('CI_Username',$_SESSION['username']);
$data['user'] = $this->session->userdata('CI_Username');
$data['title'] = ucfirst($page);
$this->load->view('templates/header');
$this->load->view('templates/nav');
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer');
print_r($data);
}
}
Upvotes: 1
Views: 128
Reputation:
When set the sessions
$sessionoptions = array('username', 'John');
$this->session->set_userdata($sessionoptions);
https://www.codeigniter.com/user_guide/libraries/sessions.html#adding-session-data
Make sure on the config.php you have set the session save path correct.
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = APPPATH . 'cache/sessions/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;
Set session folder permission 0700.
Then
$data['user'] = $this->session->userdata('username');
Upvotes: 0