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.