【发布时间】:2018-08-26 21:46:13
【问题描述】:
我在同一页面上有两个表单,一个是注册,另一个是登录,这是我的登录过程代码
public function login() {
//print_r($_POST);die;
$this->load->library('session');
$this->load->library('form_validation');
$this->form_validation->set_rules('user_name', 'User Name', 'trim|required');
$this->form_validation->set_rules('pw', 'Password', 'trim|required');
if ($this->form_validation->run() == FALSE) {
if (isset($_POST) && ($_POST['login'] == 'Login')) {
$data['login_errors'] = validation_errors();
$this->load->view('Public/register', $data);
}
} else {
$this->load->database();
$where = '';
$where = array('email' => $_POST['user_name'], 'password' => $_POST['pw']);
$rec = $this->db->select('*')->from('user')
->where($where)
->get()->result_array();
if(!empty($rec)){
$this->session->set_userdata('user',$rec);
$this->load->view('Public/profile');
}else{
$data = array(
'error_message' => 'Invalid Username or Password'
);
$this->load->view('Public/register', $data);
}
}
}
登录后的网址是 http://localhost/ci/blog/login 并查看 加载它。它看起来像 profile template
我对 codeigniter 非常陌生。为什么是 url
不改?应该是
http://localhost/ci/blog/profile
但是当我尝试重定向时
重定向(base_url()。'公共/个人资料');它
给出 404 错误。如何将其重定向到
个人资料页面并更改我的网址/个人资料。
【问题讨论】:
标签: php codeigniter