codeigniter的代码并未得到预期的结果?

新手上路,请多包涵

环境是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,运行,结果如下
Array ( [isadmin] => admin [user] => user1 )

删除临时目录下的session文件
代码复制到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... 结果如下
Array ( [admin] => 1 )
ci下运行的结果并未如预期,这是怎么回事?

阅读 1.9k
1 个回答

我试了下,发现结果都是一样的啊?!就是上面test.php文件中的结果

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏