Php Codeigniter仅以用户身份编辑自己的配置文件
我有一个问题,我可以编辑作为用户的所有配置文件。但我想,我只能编辑我的个人资料。也许你能帮我。如果我想像这样编辑我的个人资料,代码正在运行 域/成员/用户/管理/1 但是我也可以编辑/member/users/manage/2,这就是问题所在 Controller Users.phpPhp Codeigniter仅以用户身份编辑自己的配置文件,php,codeigniter,Php,Codeigniter,我有一个问题,我可以编辑作为用户的所有配置文件。但我想,我只能编辑我的个人资料。也许你能帮我。如果我想像这样编辑我的个人资料,代码正在运行 域/成员/用户/管理/1 但是我也可以编辑/member/users/manage/2,这就是问题所在 Controller Users.php public function manage($id = NULL) { if($this->session->userdata('type') == 'user') {
public function manage($id = NULL) {
if($this->session->userdata('type') == 'user') {
$data = array();
if ($id) {
$this->{$this->model}->{$this->_primary_key} = $id;
$data['item'] = $this->{$this->model}->get();
if (!$data['item'])
show_404();
} else {
$data['item'] = new Std();
}
$this->load->library("form_validation");
$this->form_validation->set_rules('username', 'Username', 'trim|required');
$this->{$this->model}->custom_select = 'users.*, teams.title as teams';
$this->{$this->model}->joins = array( 'teams' => array('teams.teams_id = users.teams_id', 'inner'));
$this->form_validation->set_rules('firstname', 'firstname', 'trim|required');
$this->form_validation->set_rules('lastname', 'lastname', 'trim');
$this->form_validation->set_rules('sex', 'sex', 'trim');
$this->form_validation->set_rules("image3", 'image3', "trim|callback_image3[$id]");
$this->form_validation->set_rules("email", 'Email', "trim|required|valid_email");
if ($id)
$this->form_validation->set_rules('password', 'Password', 'trim');
else
$this->form_validation->set_rules('password', 'Password', 'trim');
if ($this->form_validation->run() == FALSE)
$this->load->view($this->module . '/manage', $data);
else {
$this->users_model->username = $this->input->post('username');
$this->users_model->email = $this->input->post('email');
$this->users_model->firstname = $this->input->post('firstname');
$this->users_model->lastname = $this->input->post('lastname');
$this->users_model->sex = $this->input->post('sex');
if (strlen($this->input->post('password')) > 0)
$this->{$this->model}->password = md5($this->input->post('password'));
$this->{$this->model}->save();
redirect('member/' . $this->module);
}
}else{
exit('Hacking Attempt: Get out of the system ..!');
}
}
Users\u model.php
<?php
class Users_model extends CI_model
{
public $_table = 'users';
public $_primary_keys = array('user_id');
}
首先,您必须在会话中传递用户id
然后需要域/成员/用户/管理/1
你重定向到你的个人资料
如果用户控制器具有管理功能
class Users extends CI_Controller
{
public function manage($userid)
{
#checking the with session value
if(($this->session->userdata('user_id')!=$userid)):
#if not satisfied means redirect another page
redirect("Another page");
endif;
}
}
首先,您必须在会话中传递用户id
然后需要域/成员/用户/管理/1
你重定向到你的个人资料
如果用户控制器具有管理功能
class Users extends CI_Controller
{
public function manage($userid)
{
#checking the with session value
if(($this->session->userdata('user_id')!=$userid)):
#if not satisfied means redirect another page
redirect("Another page");
endif;
}
}
将角色设置为会话,并检查(role==user)是否重定向到其他页面,或发出无法编辑此详细信息的消息。出于安全目的,MD5被视为已断开,不足以进行密码哈希。使用和代替。如果您使用的是5.5之前的PHP版本,则可以使用。将角色设置为会话,并检查(角色==用户)是否重定向到其他页面,或给出无法编辑此详细信息的消息。出于安全目的,MD5被视为已断开,不足以进行密码哈希。使用和代替。如果您使用的是5.5之前的PHP版本,则可以使用。