John Davidson

php - why my sessiosn are not working in codeigniter 3?

0 comments
Message:


I am using codeigniter-3 for developing the web part, i am using sessions for maintaining the user data once the user login if i click on any page or button the page is redirect to the login page.


i have two projects of codeigniter-3 if i launch the project-1 in browser and login with credentials it's navigating to the another page it's working fine,but in project-2 it's not working but same session configurations of both project-1 and project-2.


i am facing one strange scenario if user is login in project-1 and at a same time if user has login in project-2 in same browser the page redirections are working fine in project-2 .i tried with many solutions over the google nothing works for me can you please help me to fix this issue..?


Expectation


The page should navigate one page to another page instead of redirecting to login page

congig.php


$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
// $config['sess_save_path'] = NULL;
$config['sess_save_path'] = '/tmp';

$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

LoginController.php


$userdata = array(
'id' =>$response_arr['data']['id'],
'user_id' => $response_arr['data']['user_id'],
'role' => $response_arr['data']['user_id'],
);
$this->load->library('session');
$this->session->set_userdata($userdata);


My Answer:
In CodeIgniter 3, session configuration is done in the config.php file located in the application/config directory. Make sure that the session configuration in both project-1 and project-2 is the same.

If sessions are working in project-1 but not in project-2, there might be a problem with the session configuration or the way sessions are being handled in project-2.

Here are a few things you can check and try to fix the issue:

1. Make sure that the session library is loaded in the autoload.php file located in the application/config directory:
$autoload['libraries'] = array('session');

2. Check the session save path in the php.ini file. Make sure that the session save path is writable and accessible by the web server. You can try changing the session save path in the config.php file to a different location.

3. Check if there are any conflicting session variables or session data being set in project-2 that might be causing the issue. Make sure that the session data is being set and retrieved correctly.

4. Try clearing the browser cache and cookies, as sometimes old session data can cause issues with new sessions.

5. If the issue persists, you can try using a different session driver like database or redis to see if that resolves the issue.

If none of the above solutions work, you may need to debug the session handling code in project-2 to identify the exact cause of the issue. You can use var_dump or print_r to check the session data and see if it is being set and retrieved correctly.

Rate this post

4 of 5 based on 9898 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us