环境是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下运行的结果并未如预期,这是怎么回事?
我试了下,发现结果都是一样的啊?!就是上面test.php文件中的结果