CodeIgniter $_POST 不适用于 REQUEST_URI 协议
我有一个简单的登录页面,URL 结构类似于 www.mydomain.com/admin/auth
几天前我遇到了一个问题,$_POST 始终为空,所以我用 google 搜索并找到 http://codeigniter.com/forums/viewthread/191918/ 建议更改我的config.php from:
$config['uri_protocol'] = 'REQUEST_URI';
to
$config['uri_protocol'] = 'PATH_INFO';
最后它起作用了,但只有当我在 URL 上添加 index.php 时,如下所示: www.mydomain.com/index.php/admin/auth
我试图让 $_POST 在 URL 上没有 index.php 的情况下工作,但我无法弄清楚。我的 .htaccess 是:
RewriteEngine on
RewriteCond $1 !^(index.php|assets|user_guide|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
我需要做的就是让 $_POST 在我的 URL 上工作,有什么锻炼或解决方法吗?谢谢您的宝贵时间。
编辑: 这是我的控制器(我减少了,所以它只加载视图,用于调试)
public function index()
{
$this->load->view('admin/login');
}
并且我的视图已减少为:
<?php var_dump($_POST); ?>
<html><head></head><body>
<form method='POST'>
<input type='text' name='nama' value='test'>
<input type='submit' value='Submit'>
</form>
</body></html>
并且此代码在我在没有 CI 的服务器上创建的单个文件上运行得非常好。
I have a simple login page and the URL structure is like www.mydomain.com/admin/auth
I had a problem several days ago where the $_POST had always been empty, so i googled and found http://codeigniter.com/forums/viewthread/191918/ which suggested to change my config.php from:
$config['uri_protocol'] = 'REQUEST_URI';
to
$config['uri_protocol'] = 'PATH_INFO';
And finally it worked but only when i add index.php on the URL like this:
www.mydomain.com/index.php/admin/auth
I tried to make the $_POST work without having index.php on the URL but i couldn't figure it out. My .htaccess is:
RewriteEngine on
RewriteCond $1 !^(index.php|assets|user_guide|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
All i need to do is for the $_POST to work on my URL, is there any workout or workaround? Thank you for your time.
EDIT:
Here is my controller (i reduced so it only loads the view, for debugging)
public function index()
{
$this->load->view('admin/login');
}
And my view has been reduced to this:
<?php var_dump($_POST); ?>
<html><head></head><body>
<form method='POST'>
<input type='text' name='nama' value='test'>
<input type='submit' value='Submit'>
</form>
</body></html>
And this code works perfectly fine on a single file i made on my server without CI.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过通过 $this->input->post() 访问 $_POST 数组?例如:
变成
Have you tried accessing the $_POST array through $this->input->post() ? For example:
becomes
步骤1. print_r($this->input->post());在您要发布的页面上。
Step 1. print_r($this->input->post()); on the page you are posting to.
弄清楚了,它与我的子域有关。当我禁用子域时,一切正常,它似乎与子域和 CI 的 htaccess 有关系。谢谢大家的宝贵时间:)
Figured it out, it got something to do with my subdomain. When i disable the subdomain it all works fine, it seems to have something with the htaccess of subdomain and CI. Thank you for you time all :)