Welcome Guest, Not a member yet? Register   Sign In
Session Lost on firefox in first attempt
#1

Hi, 

I have been stuck in this issues from last several days, And I have tried all the solution exists on the internet, that's why I am raising a new topic. Please help me. 

Ok so the Issue is, When the user tries to log in, so after successfully authentication (Service Hit on other server), I call the CI 3.1.11 controller method to set the session via AJAX request, and passed information in ajax request is saved into session, Which actually set (i have tested that) and once the ajax call returns and after performing another jquery function, I redirect the user to the dashboard page, now as soon as the dashboard method called (on the same controller), session destroyed Only and only in Firefox (not chrome, safari, opera ). 

Config File :
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'mcookie';
$config['sess_expiration'] =  0 ;
$config['sess_save_path'] = APPPATH.'session/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['sess_expire_on_close']  = TRUE;
$config['sess_match_useragent']  = FALSE;


$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = TRUE;
$config['cookie_httponly'] = FALSE;    (All are secure requests)


Routes.php
$route['login'] = "home/login";
$route['dashboard'] = "home/dashboard";

Autoloader file :
$autoload['libraries'] = array('form_validation', 'session');
$autoload['helper'] = array('url', 'file');

I have already altered the session.php file like commented session_start(); and lines after "security Is king" text, and started the session in index.php file at top, 

Also Changed
//OR ! preg_match('#\A'.$this->_sid_regexp.'\z#', $_COOKIE[$this->_config['cookie_name']])
to 
OR ! preg_match('/^[0-9a-f]/', $_COOKIE[$this->_config['cookie_name']])

And 
ini_set('session.name', $params['cookie_name']);
to 
ini_set('session.id', $params['cookie_name']);

But nothing works.  Also As I am saving sessions in files, So I don't see any session files created in the mentioned folder. I have tried giving 0700 and 0777 permissions.

But yes, if after successful authentication, i refresh the page several times, then session starts persisting.


Guys please please help me, I am not very good at Codeigniter and I am still learning,
Reply
#2

It seems to me that you are trying to use native PHP session. This is not necessary if you load the codeigniter session library.

If you send the corresponding excerpt from your controller it can help clarify the problem.
Reply
#3

(04-19-2021, 06:04 AM)kleber Wrote: It seems to me that you are trying to use native PHP session. This is not necessary if you load the codeigniter session library.

If you send the corresponding excerpt from your controller it can help clarify the problem.

Thank you for your response, Below is my controller code.


<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Home extends CI_Controller
{
public function __construct()
    {
        // Call the CI_Model constructor
        parent::__construct();

        // For debugging
        $this->output->enable_profiler(TRUE);
    }

    // Below method trigger via ajax
    public function setSessiondata()
    {
        $user_info = $_POST['user_info'];
        if ($user_info['screen'] == '4')
        {
            $data = array(
                'user_id' => $user_info['userid'],
                'userId' => $user_info['userid'],
                'firstName' => $user_info['fullname'],
                'fullname' => $user_info['fullname'],
                'lastName' => "",
                'email' => $user_info['email'],
                'userType' => $user_info['usertype'],
                'phoneNumber' => $user_info['phone'],
                'imageUrl' => $user_info['userprofilepic'],
                'thumbimageUrl' => $user_info['userthumbprofilepic'],
                'cityName' => $user_info['cityname'],
                'stateName' => $user_info['statename'],
                'countryName' => $user_info['countryname'],
                'extension' => $user_info['extension'],
                'extPass' => $user_info['extpass'],
                'verificationStatus' => $user_info['verificationstatus'],
                'countryId' => $user_info['countryid'],
                'client_id' => $user_info['clientid'],
                'screen' => $user_info['screen'],
            );
            $this->session->set_userdata('logged_in', $data)
        }
        else
        {
            $usrType = "Business";
            if ($user_info['screen'] == '2')
            {
                $usrType = "Individual";
            }
            $data = array(
                'firstName' => $user_info['fullname'],
                'fullname' => $user_info['fullname'],
                'lastName' => "",
                'email' => $user_info['email'],
                'userType' => $usrType,
                'screen' => $user_info['screen'],
            );

            $this->session->set_userdata('logged_in', $data)
        }

       
       
        die('true');

    }

    /* Here when I print the session information it always gives nothing  */
    public function dashboard()
    {
      /*echo 'session id =='.session_id();
        echo '<pre>';
        print_r($this->session->userdata('logged_in'));
        print_r($_COOKIE);*/
        $data = array();
        $this->load->view('admin/dashboard', $data);
    }

    public function logout()
    {
        $this->session->sess_destroy();
        redirect('login', 'refresh');
    }

}

?>


 One more thing I have recently noticed that, every time multiple session files have been created, And I am attaching a recently created session file for first attempt login.

I don't get it when a session is created and saved in the file, then why doesn't it read that file even when permission is fine (I have tried 0700 and 0777 both, 777 for testing purpose only).   


Please help me to figure out this issue. This only happens in firefox in first attempt.
Reply
#4

(04-22-2021, 01:46 AM)Aimmi1904 Wrote:
(04-19-2021, 06:04 AM)kleber Wrote: It seems to me that you are trying to use native PHP session. This is not necessary if you load the codeigniter session library.

If you send the corresponding excerpt from your controller it can help clarify the problem.

Thank you for your response, Below is my controller code.


<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Home extends CI_Controller
{
public function __construct()
    {
        // Call the CI_Model constructor
        parent::__construct();

        // For debugging
        $this->output->enable_profiler(TRUE);
    }

    // Below method trigger via ajax
    public function setSessiondata()
    {
        $user_info = $_POST['user_info'];
        if ($user_info['screen'] == '4')
        {
            $data = array(
                'user_id' => $user_info['userid'],
                'userId' => $user_info['userid'],
                'firstName' => $user_info['fullname'],
                'fullname' => $user_info['fullname'],
                'lastName' => "",
                'email' => $user_info['email'],
                'userType' => $user_info['usertype'],
                'phoneNumber' => $user_info['phone'],
                'imageUrl' => $user_info['userprofilepic'],
                'thumbimageUrl' => $user_info['userthumbprofilepic'],
                'cityName' => $user_info['cityname'],
                'stateName' => $user_info['statename'],
                'countryName' => $user_info['countryname'],
                'extension' => $user_info['extension'],
                'extPass' => $user_info['extpass'],
                'verificationStatus' => $user_info['verificationstatus'],
                'countryId' => $user_info['countryid'],
                'client_id' => $user_info['clientid'],
                'screen' => $user_info['screen'],
            );
            $this->session->set_userdata('logged_in', $data)
        }
        else
        {
            $usrType = "Business";
            if ($user_info['screen'] == '2')
            {
                $usrType = "Individual";
            }
            $data = array(
                'firstName' => $user_info['fullname'],
                'fullname' => $user_info['fullname'],
                'lastName' => "",
                'email' => $user_info['email'],
                'userType' => $usrType,
                'screen' => $user_info['screen'],
            );

            $this->session->set_userdata('logged_in', $data)
        }

       
       
        die('true');

    }

    /* Here when I print the session information it always gives nothing  */
    public function dashboard()
    {
      /*echo 'session id =='.session_id();
        echo '<pre>';
        print_r($this->session->userdata('logged_in'));
        print_r($_COOKIE);*/
        $data = array();
        $this->load->view('admin/dashboard', $data);
    }

    public function logout()
    {
        $this->session->sess_destroy();
        redirect('login', 'refresh');
    }

}

?>


 One more thing I have recently noticed that, every time multiple session files have been created, And I am attaching a recently created session file for first attempt login.

I don't get it when a session is created and saved in the file, then why doesn't it read that file even when permission is fine (I have tried 0700 and 0777 both, 777 for testing purpose only).   


Please help me to figure out this issue. This only happens in firefox in first attempt.

Thanks. Do you have any open repositories with this code? I would like to analyze it as a "whole" and do some tests here. Send me the link to this repository by private message if you think it's convenient.
Reply
#5

(04-28-2021, 04:48 AM)kleber Wrote:
(04-22-2021, 01:46 AM)Aimmi1904 Wrote:
(04-19-2021, 06:04 AM)kleber Wrote: It seems to me that you are trying to use native PHP session. This is not necessary if you load the codeigniter session library.

If you send the corresponding excerpt from your controller it can help clarify the problem.

Thank you for your response, Below is my controller code.


<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Home extends CI_Controller
{
public function __construct()
    {
        // Call the CI_Model constructor
        parent::__construct();

        // For debugging
        $this->output->enable_profiler(TRUE);
    }

    // Below method trigger via ajax
    public function setSessiondata()
    {
        $user_info = $_POST['user_info'];
        if ($user_info['screen'] == '4')
        {
            $data = array(
                'user_id' => $user_info['userid'],
                'userId' => $user_info['userid'],
                'firstName' => $user_info['fullname'],
                'fullname' => $user_info['fullname'],
                'lastName' => "",
                'email' => $user_info['email'],
                'userType' => $user_info['usertype'],
                'phoneNumber' => $user_info['phone'],
                'imageUrl' => $user_info['userprofilepic'],
                'thumbimageUrl' => $user_info['userthumbprofilepic'],
                'cityName' => $user_info['cityname'],
                'stateName' => $user_info['statename'],
                'countryName' => $user_info['countryname'],
                'extension' => $user_info['extension'],
                'extPass' => $user_info['extpass'],
                'verificationStatus' => $user_info['verificationstatus'],
                'countryId' => $user_info['countryid'],
                'client_id' => $user_info['clientid'],
                'screen' => $user_info['screen'],
            );
            $this->session->set_userdata('logged_in', $data)
        }
        else
        {
            $usrType = "Business";
            if ($user_info['screen'] == '2')
            {
                $usrType = "Individual";
            }
            $data = array(
                'firstName' => $user_info['fullname'],
                'fullname' => $user_info['fullname'],
                'lastName' => "",
                'email' => $user_info['email'],
                'userType' => $usrType,
                'screen' => $user_info['screen'],
            );

            $this->session->set_userdata('logged_in', $data)
        }

       
       
        die('true');

    }

    /* Here when I print the session information it always gives nothing  */
    public function dashboard()
    {
      /*echo 'session id =='.session_id();
        echo '<pre>';
        print_r($this->session->userdata('logged_in'));
        print_r($_COOKIE);*/
        $data = array();
        $this->load->view('admin/dashboard', $data);
    }

    public function logout()
    {
        $this->session->sess_destroy();
        redirect('login', 'refresh');
    }

}

?>


 One more thing I have recently noticed that, every time multiple session files have been created, And I am attaching a recently created session file for first attempt login.

I don't get it when a session is created and saved in the file, then why doesn't it read that file even when permission is fine (I have tried 0700 and 0777 both, 777 for testing purpose only).   


Please help me to figure out this issue. This only happens in firefox in first attempt.

Thanks. Do you have any open repositories with this code? I would like to analyze it as a "whole" and do some tests here. Send me the link to this repository by private message if you think it's convenient.


Hi,

Once again thank you for your reply. But sorry I can share the repo or code because of the company policy and all, (I guess you understand my problem).  But one thing I noticed very recently that if I try to save session information using PHP (means from CodeIgniter controller's method), then it will persist, but when I send a request to the controller method to save session information, only then doesn't work on redirect.
I don't know that CodeIgniter support ajax to save session information or not.


Another thing is, I see 3 different session files created in my session folder, all with different __ci_last_regenerate IDs. 

I hope this information could help you to guide me.


I am really really thankful for all your replies.
Reply
#6

I understand. Check out these links and tell me if they help you:

https://stackoverflow.com/a/52510654

https://www.moreofless.co.uk/using-nativ...deigniter/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB