我有的管理员控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Admin extends CI_controller{
public function __construct(){
parent::__construct();
$this->load->model('common');
$this->load->library('session');
}
public function index(){
$this->load->view("login");
}
public function matched(){
$this->form_validation->set_rules('name','Name','required');
$this->form_validation->set_rules('pass','Password','required');
if($this->form_validation->run()==FALSE){
$error['error']=validation_errors();
$this->load->view('login',$error);
}
else{
$name= $this->input->post('name');
$pass=$this->input->post('pass');
$result=$this->common->match_data($name,$pass);
if(!empty($result)){
$data=array(
'id'=>$result[0]->id,
'name'=>$result[0]->name,
'type'=>$result[0]->type,
'logged_in'=>TRUE
);
$this->session->set_userdata($data);
redirect('dashboard');
}
else{
$this->load->view('login');
}
}
}
public function logoutuser(){
$this->session->sess_destroy();
redirect("admin","refresh");
}
}
?>
仪表板控制器:
<?php
class Dashboard extends CI_controller{
public function __construct(){
parent::__construct();
$this->load->model('common');
}
public function index(){
$this->load->view('dashboard');
}
}
?>
仪表板页面或视图页面:
<?php
//echo "<pre>";print_r($this->session->all_userdata());exit;
$name=$this->session->userdata('name');
$id=$this->session->userdata('id');
$type=$this->session->userdata('type');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>SB Admin - Bootstrap Admin Template</title>
<!-- Bootstrap Core CSS -->
<link href="<?php echo base_url();?>assets/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="<?php echo base_url();?>assets/css/sb-admin.css" rel="stylesheet">
<!-- Morris Charts CSS -->
<link href="<?php echo base_url();?>assets/css/plugins/morris.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="<?php echo base_url();?>assets/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href=""><?php echo "User"."-".ucwords($type); ?></a>
</div>
<!-- Top Menu Items -->
<ul class="nav navbar-right top-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-envelope"></i> <b class="caret"></b></a>
<ul class="dropdown-menu message-dropdown">
<li class="message-preview">
<a href="#">
<div class="media">
<span class="pull-left">
<img class="media-object" src="http://placehold.it/50x50" alt="">
</span>
<div class="media-body">
<h5 class="media-heading"><strong><?php echo $name;?></strong>
</h5>
<p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
<p>Lorem ipsum dolor sit amet, consectetur...</p>
</div>
</div>
</a>
</li>
<li class="message-preview">
<a href="#">
<div class="media">
<span class="pull-left">
<img class="media-object" src="http://placehold.it/50x50" alt="">
</span>
<div class="media-body">
<h5 class="media-heading"><strong><?php echo $name;?></strong>
</h5>
<p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
<p>Lorem ipsum dolor sit amet, consectetur...</p>
</div>
</div>
</a>
</li>
<li class="message-preview">
<a href="#">
<div class="media">
<span class="pull-left">
<img class="media-object" src="http://placehold.it/50x50" alt="">
</span>
<div class="media-body">
<h5 class="media-heading"><strong><?php echo $name;?></strong>
</h5>
<p class="small text-muted"><i class="fa fa-clock-o"></i> Yesterday at 4:32 PM</p>
<p>Lorem ipsum dolor sit amet, consectetur...</p>
</div>
</div>
</a>
</li>
<li class="message-footer">
<a href="#">Read All New Messages</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-bell"></i> <b class="caret"></b></a>
<ul class="dropdown-menu alert-dropdown">
<li>
<a href="#">Alert Name <span class="label label-default">Alert Badge</span></a>
</li>
<li>
<a href="#">Alert Name <span class="label label-primary">Alert Badge</span></a>
</li>
<li>
<a href="#">Alert Name <span class="label label-success">Alert Badge</span></a>
</li>
<li>
<a href="#">Alert Name <span class="label label-info">Alert Badge</span></a>
</li>
<li>
<a href="#">Alert Name <span class="label label-warning">Alert Badge</span></a>
</li>
<li>
<a href="#">Alert Name <span class="label label-danger">Alert Badge</span></a>
</li>
<li class="divider"></li>
<li>
<a href="#">View All</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> <?php echo $name;?><b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a href="#"><i class="fa fa-fw fa-user"></i> Profile</a>
</li>
<li>
<a href="#"><i class="fa fa-fw fa-envelope"></i> Inbox</a>
</li>
<li>
<a href="#"><i class="fa fa-fw fa-gear"></i> Settings</a>
</li>
<li class="divider"></li>
<li>
<a href="<?php echo base_url();?>admin/logoutuser"><i class="fa fa-fw fa-power-off"></i> Log Out</a>
</li>
</ul>
</li>
</ul>
<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li class="active">
<a href="index.html"><i class="fa fa-fw fa-dashboard"></i> Dashboard</a>
</li>
<li>
<a href="charts.html"><i class="fa fa-fw fa-bar-chart-o"></i> Charts</a>
</li>
<li>
<a href="tables.html"><i class="fa fa-fw fa-table"></i> Tables</a>
</li>
<li>
<a href="forms.html"><i class="fa fa-fw fa-edit"></i> Forms</a>
</li>
<li>
<a href="bootstrap-elements.html"><i class="fa fa-fw fa-desktop"></i> Bootstrap Elements</a>
</li>
<li>
<a href="bootstrap-grid.html"><i class="fa fa-fw fa-wrench"></i> Bootstrap Grid</a>
</li>
<li>
<a href="javascript:;" data-toggle="collapse" data-target="#demo"><i class="fa fa-fw fa-arrows-v"></i> Dropdown <i class="fa fa-fw fa-caret-down"></i></a>
<ul id="demo" class="collapse">
<li>
<a href="#">Dropdown Item</a>
</li>
<li>
<a href="#">Dropdown Item</a>
</li>
</ul>
</li>
<li>
<a href="blank-page.html"><i class="fa fa-fw fa-file"></i> Blank Page</a>
</li>
<li>
<a href="index-rtl.html"><i class="fa fa-fw fa-dashboard"></i> RTL Dashboard</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Dashboard <small>Statistics Overview</small>
</h1>
<ol class="breadcrumb">
<li class="active">
<i class="fa fa-dashboard"></i> Dashboard
</li>
</ol>
</div>
</div>
<!-- /.row -->
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="<?php echo base_url();?>assets/js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<?php echo base_url();?>assets/js/bootstrap.min.js"></script>
<!-- Morris Charts JavaScript -->
<script src="<?php echo base_url();?>assets/js/plugins/morris/raphael.min.js"></script>
<script src="<?php echo base_url();?>assets/js/plugins/morris/morris.min.js"></script>
<script src="<?php echo base_url();?>assets/js/plugins/morris/morris-data.js"></script>
</body>
</html>
问题是,当我点击浏览器后退按钮时,它会将我带回登录用户..但是我需要使用codeigniter禁用浏览器后退按钮而不使用javascript
答案 0 :(得分:0)
在codeigniter中无法禁用浏览器的后退按钮。 虽然有其他方法可以在将会话销毁到我们想要的页面时重定向用户。
在视图中检查会话变量,控制器是否正常工作..
echo $_SESSION['session_varibalename'];
此外,您也可以看到此链接:how to disable the back button in codeigniter?
<?php
class Dashboard extends CI_controller{
public function __construct(){
parent::__construct();
$this->load->model('common');
$this->load->library('session');
}
public function index(){
$logged_in = $this->session->userdata('logged_in');
if($logged_in == TRUE || empty($logged_in))
{
//user not logged in
$this->session->set_flashdata('error', 'Session has Expired');
//it will redirect the user to the Admin controller to index function which will call the login view.
redirect('Admin/index');
}
else
{
//user Logged in
$this->load->view('dashboard');
}
}
}
答案 1 :(得分:0)
您需要检查控制器中的会话
<?php
class Dashboard extends CI_controller{
public function __construct(){
parent::__construct();
$this->load->model('common');
$this->load->library('session');
}
public function index(){
if($this->session->all_userdata()){
$this->load->view('dashboard');
}
else{
redirect('lofin_contoller');
}
}
}
?>