CodeIgniter 无法读取任何 POST
CodeIgniter can't read any POST
Whatever/however i post 通过 CodeIgniter 中的 HTML 表单 - 我的 $_POST
和 $_REQUEST
数组是空的。但是,当 method 设置为 get
时,一切看起来都很好。
我知道我的问题与 Apache / .htaccess 或 URI 设置有关。我 运行 XAMPP Windows 7.
<form method='post' action='auth/login'>
<input type='submit' name='login' value='TEST' />
</form>
现在在控制器 auth
函数中 login
应该 return 我
Array( 'login' => 'TEST' );
我得到的是
Array( );
我已经尝试过什么让它读取 $_POST
?
- 我已尝试设置我的 ALL
uri_protocol
设置。
- 在
''
和 'index.php'
上尝试了 CodeIgniter 配置 index_page
- 尝试了很多不同的 .htaccess 方法。
- 检查过我的 apache
mod_rewrite
是 included/allowed,确实是。
- 检查允许重写在 apache/conf/httpd.conf
中的任何地方都设置为 All
- 试图用
$this->input->post()
阅读 $_POST
- 将动作路径设为绝对路径,还是没有。
- 尝试 post 从外部脚本到 CodeIgniter index.php
一切都是徒劳。而且我知道问题一定出在 Apache 设置上,导致所有其他没有 .htaccess 的 folders/projects 都能正常工作。
所以这是我尝试过的准确的 .htaccess 内容,4me 效果最好:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L] # returns 404 everywhere.
RewriteRule .* index.php/[=14=] [PT,L] # Pages work good!
^^ 这个效果最好(至少我得到了网页 运行)但不是 $_POST
.
想看控制器(auth.php)代码的人:
class auth extends CI_Controller {
function __construct() {
# Parent constructor.
parent::__construct();
}
function login() {
# Trying to read post
print_r($_POST);
print_r($this->input->post());
# Loading form.
$this->load->view('login_page');
}
}
试试这个删除你的操作并添加 enctype
<form name="login" id="login" action="" method="post" enctype="multipart/form-data">
<input type='submit' name='login' value='TEST' />
</form>
并在您的控制器中
在当前操作中添加以下代码。
if($this->input->post()){
echo "<pre>";print_r($this->input->post());die;
}
好的,这是我的解决方案:
我覆盖了 CI_Model 以始终检查是否有 $this->input->post('login')
,如果有,检查是否有 posted 用户并通过验证。如果它不验证 redirect
到登录页面。 redirect
清除了我所有的 post。
感谢所有试图提供帮助的人,我深表歉意。
Whatever/however i post 通过 CodeIgniter 中的 HTML 表单 - 我的 $_POST
和 $_REQUEST
数组是空的。但是,当 method 设置为 get
时,一切看起来都很好。
我知道我的问题与 Apache / .htaccess 或 URI 设置有关。我 运行 XAMPP Windows 7.
<form method='post' action='auth/login'>
<input type='submit' name='login' value='TEST' />
</form>
现在在控制器 auth
函数中 login
应该 return 我
Array( 'login' => 'TEST' );
我得到的是
Array( );
我已经尝试过什么让它读取 $_POST
?
- 我已尝试设置我的 ALL
uri_protocol
设置。 - 在
''
和'index.php'
上尝试了 CodeIgniter 配置 - 尝试了很多不同的 .htaccess 方法。
- 检查过我的 apache
mod_rewrite
是 included/allowed,确实是。 - 检查允许重写在 apache/conf/httpd.conf 中的任何地方都设置为
- 试图用
$this->input->post()
阅读 - 将动作路径设为绝对路径,还是没有。
- 尝试 post 从外部脚本到 CodeIgniter index.php
index_page
All
$_POST
一切都是徒劳。而且我知道问题一定出在 Apache 设置上,导致所有其他没有 .htaccess 的 folders/projects 都能正常工作。
所以这是我尝试过的准确的 .htaccess 内容,4me 效果最好:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L] # returns 404 everywhere.
RewriteRule .* index.php/[=14=] [PT,L] # Pages work good!
^^ 这个效果最好(至少我得到了网页 运行)但不是 $_POST
.
想看控制器(auth.php)代码的人:
class auth extends CI_Controller {
function __construct() {
# Parent constructor.
parent::__construct();
}
function login() {
# Trying to read post
print_r($_POST);
print_r($this->input->post());
# Loading form.
$this->load->view('login_page');
}
}
试试这个删除你的操作并添加 enctype
<form name="login" id="login" action="" method="post" enctype="multipart/form-data">
<input type='submit' name='login' value='TEST' />
</form>
并在您的控制器中
在当前操作中添加以下代码。
if($this->input->post()){
echo "<pre>";print_r($this->input->post());die;
}
好的,这是我的解决方案:
我覆盖了 CI_Model 以始终检查是否有 $this->input->post('login')
,如果有,检查是否有 posted 用户并通过验证。如果它不验证 redirect
到登录页面。 redirect
清除了我所有的 post。
感谢所有试图提供帮助的人,我深表歉意。