|  | 
 
| addView页面中提交数据后,调用add函数,然后添加到数据库,但现在我直接在URL中输入 localhost/user/add
 这样也可以直接添加一条数据...
 mysql> select * from users;
 +----+----------+------+------+
 | id | name     | age  | sex  |
 +----+----------+------+------+
 | 41 | fhfdhdfg | 345  | 1    |
 +----+----------+------+------+
 直接访问localhost/user/add后
 mysql> select * from users;
 +----+----------+------+------+
 | id | name     | age  | sex  |
 +----+----------+------+------+
 | 41 | fhfdhdfg | 345  | 1    |
 | 43 | 0        | 0    | 0    |
 +----+----------+------+------+
 也已经配置了
 $config['global_xss_filtering'] = TRUE;
 然后删除的函数,我直接访问localhost/user/delete/43
 也可以直接把数据给删除了...
 有什么办法可以防止上面这2种情况吗??
 还有...我add_success页面里使用
 
 JS复制代码 复制代码<script type=text/javascript>var t=3;
 function later_back() {
 backL.innerHTML=t;
 t--;
 if (t==0)
 location.href = 'show';
 setTimeout("later_back();",1000);
 }
 later_back();
 </script>
可以成功的将页面导向到localhost/user/show
 可是在del_success页面中
 同样的代码却不行
 add_success页面的URL是localhost/user/add_success
 而del_success页面的URL是localhost/user/delete/id
 如果我直接使用上面的JS,则它3秒后跳转到
 localhost/user/delete/show(这页面肯定是没有的...)
 让我不得不在localhost.href中直接写localhost/user/show
 
 
 SQL复制代码 复制代码+-------+------------------------------------------------------------------------| TABLE | CREATE TABLE
 +-------+------------------------------------------------------------------------
 | users | CREATE TABLE `users` (
 `id` INT(8) NOT NULL AUTO_INCREMENT,
 `name` VARCHAR(30) CHARACTER SET utf8 DEFAULT NULL,
 `age` VARCHAR(3) CHARACTER SET utf8 DEFAULT NULL,
 `sex` VARCHAR(2) CHARACTER SET utf8 DEFAULT NULL,
 PRIMARY KEY (`id`)
 ) ENGINE=MyISAM AUTO_INCREMENT=43 DEFAULT CHARSET=utf8 COLLATE=utf8_estonian_ci |
 +-------+------------------------------------------------------------------------
PHP复制代码 复制代码 
<?php
 class User extends  Controller {
  function  User() { 
   parent::Controller();
  }
  
  function  index() {
   $data = array('title'  => 'User System',
          'message' => 'Welcome to User System!'
          );
   $this->load->view('index',$data);
  }
  
  function  addView() {
   $data = array('title'  => '添加用户',
          'message' => '添加新用户到当前系统。'
          );
   $this->load->view('user_view_add',$data);
  }
  
  function  add() {
   $this->load->model('User_Model','User');
   $this->User->addUser(); 
   redirect('user/add_success','refresh');
  }
  
  function  add_success() {
   $data = array('title' => '添加用户成功',
          'message' => '添加用户成功!'
          );
   $this->load->view('add_success',$data);
  }
  
  function  show() {
   $this->load->model('User_Model','User');
   $result = $this->User->showUser();
   $data = array('title' => '用户列表',
          'message' => '以下是当前所有用户:',
          'values' => $result
          );
   $this->load->view('user_view_show',$data);
  }
  
  function  delete($id) {
   $this->load->model('User_Model','User');
   $this->User->delUser($id);
   $data = array('title' => '删除用户成功',
          'message' => '删除用户成功!'
          );
   $this->load->view('del_success',$data);
  }
 }
?>PHP复制代码 复制代码 
<?php
 class User_Model extends  Model {
  function  User_Model() { 
   parent::Model();
  }
  
  function  addUser() {
   $data = array('name' => $this->input->post('name'),
          'age' => $this->input->post('age'),
          'sex' => $this->input->post('sex'),
   );
   
   $this->db->insert('users',$data);
  }
  
  function  showUser() {
   $query = $this->db->get('users');
   return $query->result();
  }
  
  function  delUser($id) {
   $query = $this->db->delete('users',array('id' => $id));
  }
 }
?> | 
 |