|
<?php
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 **/
echo "Session id ".session_id();
if (isset($_SESSION['user_name'])) {
$this->display("welcom");
} else {
$this->display("login");
}
}
public function login()
{
echo "Session id ".session_id();
$_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");
}
}
上面是controller的源码,逻辑是这样,首次访问时,会调用index函数,因为$_SESSION['user_name'] 没有设置,会显示login页面。当Login提交后,设置$_SESSION['user_name'] 并显示welcom页面。
现在有个问题:
index时的Session ID和login页面提交时(login函数)的Session ID不一样,为什么?怎么保持一致?难道要在index中记录SessionID并传给login函数吗?
|
|