Why does the following code and Session change in the CodeIgniter template?

Source: Internet
Author: User
Why does the following code and Session change in the CodeIgniter template? Defined ("BASEPATH") OR exit ("No direct script access allowed ");
/**
* Admin of the content
*/

Class Admin extends CI_Controller {
Private $ signature;
Public function _ construct ()
{
Parent: :__ construct ();
$ This-> load-> helper ("url_helper ");
$ This-> load-> library ("session ");
// Session_start ();
}

Public function index ()
{
/** Login each time visit **/
If (isset ($ _ SESSION ['User _ name']) {
$ This-> display ("welcom ");
} Else {
$ This-> display ("login ");
}
}

Public function login ()
{
$ _ SESSION ['User _ name'] = $ this-> input-> post ("user_name ");
$ This-> display ("welcom ");
}

Private function display ($ pages)
{
$ This-> load-> view ("templates/header", $ data );
$ This-> load-> view ("admin/$ pages", $ data );
$ This-> load-> view ("templates/footer ");
}
}

Based on the CodeIgniter Template framework, the logic of the controller code above is: when the first access is made, the index function is called to display the login page if $ _ SESSION ['User _ name'] is not set, the login page submits data to the login function and sets $ _ SESSION ['User _ name'] in the login function.
The problem is:
1. the session_id () accessed for the first time is inconsistent with the session_id () of the login function after the logon page is submitted. Why?
2. this raises another issue. if you open another tab (equivalent to a window) and re-access it (the index function is called at this time ), $ _ SESSION ['User _ name'] is not set. you must log on again.
How can this problem be solved?


Reply to discussion (solution)

No one ever met?

Session. auto_start = 0 in php. ini

Session. auto_start = 0 in php. ini


This is not the reason. I don't need CI. the test code I wrote does not have this problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.