在我的登录控制器上,我正在尝试($this->input->server('REQUEST_METHOD') == 'POST')
提交表单而不是codeigniter form_validation
但是当我使用 redirect()时,它不会重定向。
问题:为什么在使用($this->input->server('REQUEST_METHOD')
提交表单时重定向无法正常工作?什么是让它发挥作用的最佳解决方案。
更新:似乎没有提交表单,因为我使用$config['uri_protocol'] = 'QUERY_STRING';
代替$config['uri_protocol'] = 'REQUEST_URI';
但需要使用$config['uri_protocol'] = 'QUERY_STRING';
routes.php文件
$route['route=common/login'] = 'admin/common/login/index';
$route['route=common/dashboard&token=(:any)'] = 'admin/common/dashboard/index';
$route['route=common/logout&token=(:any)'] = 'admin/common/logout/index';
CONFIG.PHP
$config['base_url'] = 'http://localhost/project-cms/admin/';
$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING';
登录控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends MX_Controller {
public function index()
{
if ($this->input->server('REQUEST_METHOD') == 'POST') {
$token = md5(mt_rand());
$url_token = '&token=' . $token;
echo "working";
//redirect('index.php?route=common/dashboard' . $url_token);
//$this->response->redirect($this->url->link('common/dashboard', $url_token, 'SSL'));
}
$data['action'] = $this->url->link('common/login', '', 'SSL');
$this->load->view('template/common/login', $data);
}
}
登录视图
<form enctype="multipart/form-data" method="post" action="<?php echo $action;?>">
<input type="text" name="username" />
<input type="submit" value="Submit" />
</form>
版本: Codeigniter 3&amp; XAMPP使用Windows 7
答案 0 :(得分:0)
REQUEST_METHOD
与您的重定向问题无关
您使用错误的方法来定义路线。
$route['common/login'] = 'admin/common/login/index';
$route['common/dashboard/(:any)'] = 'admin/common/dashboard/index/$1';
$route['common/logout/(:any)'] = 'admin/common/logout/index/S1';
你将获得你的令牌(在你的控制器中),
public function index($token)
{
echo $token;
}
将您的登录控制器更改为
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends MX_Controller {
public function index()
{
if ($this->input->server('REQUEST_METHOD') == 'POST') {
$token = md5(mt_rand());
redirect('common/dashboard/' . $url_token);
}
$data['action'] = $this->url->link('common/login', '', 'SSL');
$this->load->view('template/common/login', $data);
}
}