Session lost after redirect in Codeigniter

前端 未结 13 2393
清歌不尽
清歌不尽 2021-02-05 06:39

I\'m using codeigniter as a framework.

Firstly, I use localhost but when I change to my IP address the login function doesn\'t work anymore. I found that th

相关标签:
13条回答
  • 2021-02-05 06:48

    From my experience, the problems can be:

    1. one (or more) of your files ain't 'UTF-8 with BOM' (if your website won't be only English and use UTF-8 as encoding like mine). You must change all the files to 'UTF-8 with BOM'. Notepad++ will help.
    2. there are some characters before php tag or after ?> (better take ?> out). Please be sure there are no any characters include space.
    3. When call localhost/xxxxxx as the address, change it to 127.0.0.1/xxxxxx or your LAN IP
    4. I always store sessions in DB instead of file (easier for debuging).
    0 讨论(0)
  • 2021-02-05 06:54

    You should add one thing to your autoload.php file.

    $autoload['libraries'] = array('database','session');

    this will solve your session re-direction problem

    0 讨论(0)
  • 2021-02-05 06:56

    Session lost after redirect in Codeigniter

    I found the problem too.

    You still met the problem. Please notice the session’s direction of the codeigniter. When your browser visited your website and refresh a few time, the codeigniter generated more session files under the session direction of the codeigniter.

    You remand load library session on your controller file.

    Please refer the following config.php setting.

    When you change the about setting, please remove or clear all offline data of your browser and all sessions file of the codeigniter. Then you try to do again. It is maybe repair the problem.

    If you can't still repair the problem. You can download the codeigniter package from codeigniter.org again and then extract the package for testing environment.

    0 讨论(0)
  • 2021-02-05 06:58

    I was shocked at first when I encountered this problem. It happened to me because my session data had an @ sign.

    The solution is to simply encode the data using base64_encode.

    Eg:

    $Data = urlencode(  base64_encode($Email) );
    $this->session->set_userdata('Data', $Data);
    

    And to reuse it, simply do this:

    $Data = base64_decode( urldecode( $this->session->userdata('Data') ) );
    

    Hope this helps.

    NEW FINDING: This problem still persists on some browsers and devices. So this is not really a solution anymore. For example, it works on Samsung Android, MicroMAX Android but not on Huawei Android.

    0 讨论(0)
  • 2021-02-05 07:00

    I solved this problem by configuring the $config['cookie_domain'] to localhost

    $config['cookie_domain']    = "localhost";
    

    i initially had that variable set to fully qualified domain name such as www.exampledomain.com but meanwhile i was using a local server.

    The domain that your script is running under should be the same as the domain set under $config['cookie_domain] to avoid unexpected failure with codeigniter session class.

    0 讨论(0)
  • 2021-02-05 07:00

    I had the same issue, in my case that was insufficient permissions for sessions folder. Please check php.ini for session.save_path and config.php for $config['sess_save_path'] and make sure the folder has 777 or 757 set as permissions.

    0 讨论(0)
提交回复
热议问题