鍍金池/ 問答/PHP  網(wǎng)絡(luò)安全/ codeigniter的代碼并未得到預(yù)期的結(jié)果?

codeigniter的代碼并未得到預(yù)期的結(jié)果?

環(huán)境是windows,php5.5,codeigniter 3.1.8
代碼如下:

<?php
        session_start();
        $_SESSION['admin']="1";
        $str =array("_SESSION"=>array("isadmin"=>"admin","user"=>"user1"));
        extract($str);
        print_r($_SESSION);

保存為test.php,運行,結(jié)果如下
Array ( [isadmin] => admin [user] => user1 )

刪除臨時目錄下的session文件
代碼復(fù)制到ci的welcome.php,如下

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

class Welcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        $this->load->view('welcome_message');
    }
    public function test()
    {
        session_start();
        $_SESSION['admin']="1";
        $str =array("_SESSION"=>array("isadmin"=>"admin","user"=>"user1"));
        extract($str);
        print_r($_SESSION);
    }
    
}

運行http://localhost/index.php/we... 結(jié)果如下
Array ( [admin] => 1 )
ci下運行的結(jié)果并未如預(yù)期,這是怎么回事?

回答
編輯回答
空痕

我試了下,發(fā)現(xiàn)結(jié)果都是一樣的啊?!就是上面test.php文件中的結(jié)果

2018年4月18日 06:45