CodeIgniter $_POST 不适用于 REQUEST_URI 协议

发布于 2025-01-02 10:28:01 字数 1230 浏览 0 评论 0原文

我有一个简单的登录页面,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不如归去 2025-01-09 10:28:01

您是否尝试过通过 $this->input->post() 访问 $_POST 数组?例如:

$_POST['foo']

变成

$this->input->post('foo')

Have you tried accessing the $_POST array through $this->input->post() ? For example:

$_POST['foo']

becomes

$this->input->post('foo')
缱绻入梦 2025-01-09 10:28:01

步骤1. print_r($this->input->post());在您要发布的页面上。

Step 1. print_r($this->input->post()); on the page you are posting to.

撩人痒 2025-01-09 10:28:01

弄清楚了,它与我的子域有关。当我禁用子域时,一切正常,它似乎与子域和 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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文