我试图在Codeigniter php上创建一个会话示例,这是我的Sesion_controller.php代码。
class Session_controller extends CI_Controller {
public function index() {
//loading session library
$this->load->library('session');
//adding data to session
$this->session->set_userdata('name','ABC');
$this->load->view('session_view');
}
public function unset_session_data() {
//loading session library
$this->load->library('session');
//removing session data
$this->session->unset_userdata('name');
$this->load->view('session_view');
}
}
这是我的Session-view.php代码
<body>
Welcome <?php echo $this->session->userdata('name'); ?>
<br>
<a href = 'http://localhost:8081/codeigniterPhp/index.php/sessionex/unset'>
Click Here</a> to unset session data.
</body>
以下是我在routes.php文件中所做的更改
$route['sessionex'] = 'Session_Controller';
在本地服务器中运行此代码后,视图页面正常运行,但我在控制器页面中遇到错误,即localhost拒绝连接
更改路线:
$route['sessionex'] = 'Session_Controller/index';
$route['sessionex/unset'] = 'Session_Controller/unset_session_data';