【发布时间】:2021-02-27 15:01:54
【问题描述】:
我正在 Codeigniter 3.1.8 和 Bootstrap 4 中开发基本的 blog application。
我在这个应用程序中添加了一个注册和登录系统。我目前正在研究密码重置系统。
在Changepasword控制器中,index方法接受参数$email和$token:
public function index($email, $token) {
$data = $this->Static_model->get_static_data();
$data['pages'] = $this->Pages_model->get_pages();
$data['tagline'] = 'New password';
$data['categories'] = $this->Categories_model->get_categories();
// Form validation rules
$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]');
$this->form_validation->set_rules('cpassword', 'Confirm password', 'required|matches[password]');
$this->form_validation->set_error_delimiters('<p class="error-message">', '</p>');
if(!$this->form_validation->run()) {
$this->load->view('partials/header', $data);
$this->load->view('auth/newpassword');
$this->load->view('partials/footer');
} else {
$this->Usermodel->set_new_password($email, $token);
}
}
在路由文件中,上面的控制器有这一行:
$route['changepasword/(:any)/(:any)'] = 'changepasword/$1/$2/';
整个路由文件:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'posts';
$route['install'] = 'install';
$route['migrate'] = 'migrate';
$route['register'] = 'register';
$route['login'] = 'login';
$route['newpassword'] = 'newpassword';
$route['changepasword'] = 'changepasword';
$route['changepasword/(:any)/(:any)'] = 'changepasword/$1/$2/';
$route['dashboard'] = 'dashboard';
$route['dashboard/create-post'] = 'dashboard/posts/create';
$route['dashboard/create-page'] = 'dashboard/pages/create';
$route['dashboard/create-category'] = 'dashboard/categories/create';
$route['dashboard/manage-authors'] = 'dashboard/users';
$route['404_override'] = '';
$route['categories/posts/(:any)'] = 'categories/posts/$1';
$route['(:any)'] = 'posts/post/$1';
$route['translate_uri_dashes'] = FALSE;
我也将此添加到config.php 文件中:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_()@=&\-!';
然而,在 URL http://ciblog.com/changepasword/myaddress@gmail.com/f450469ac1970b06074acb7c430d431d 而不是正在呈现的视图上,我得到了错误:
404 Page Not Found
The page you requested was not found.
如果我使用 md5($this->user_email) 而不是 $this->user_email 我会得到 URL:http://ciblog.com/changepasword/ec9814883d7f7149bc15f1ed1f472da9/d7571dc4e25ea76278bee5eb45251f11,但仍然是 404 Page Not Found 错误消息。
到目前为止,我为此更新密码功能编写的所有代码都是 HERE。
我做错了什么?
【问题讨论】:
-
@ 符号在 URL 中无效。我认为 token 足以识别用户。
-
@AdamP。我将此添加到配置中:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_()@=&\-!';. -
这个技巧不起作用,因为这是浏览器中的安全规则,它与 Codeigniter 无关。
-
@AdamP。如果我 md5 电子邮件并获得类似
http://mysite.co.uk/changepasword/ec9814883d7f7149bc15f1ed1f472da9/08c981bc4f279a485b210c9b7d6741bf的 URL,也会发生同样的情况 -
您的 repo 不是最新的(最后一次提交:6 天前)。请更新 repo,我检查整个代码
标签: php codeigniter codeigniter-3