Post array always empty on CodeIgniter application running on nginx
I have nginx 1.0.2 installed on Ubuntu 11 with php 5.3.5 running with FPM/FastCGI.
On a codeigniter applilcation of mine i get the following problem. I have a simple login form with a username and password field. When I submit the form the $_POST array is empty. So is $this->input->post('username') and $this->input->post('password').
The application works fine on apache. I tried creating a simple test form on a simple php file and $_POST data worked perfectly. I can provide c开发者_Python百科onfiguration files if needed. Any ideas ?
Update: It finally worked. There were some redirects in my vhost config which were causing loss of post data. The working vhost config can be found here: http://codeigniter.com/forums/viewthread/90231/#455528
I think I know the issue now. The fact that it's returning 404 and processing your script tells me that the error_page is what's doing the 'rewrite' to get the request to /index.php. An error_page to a non-named location will transform the request into a GET, so the error_page 404 /index.php is doing an internal redirect to /index.php, but it's stripping the request body in the process (and the lack of an = means the status code isn't overridden by the error_page target). I'm not sure why all those ifs aren't performing the redirect (if processing in nginx is really weird, so it's a good idea to avoid them), but I think if you use a named location for your error page, that will preserve the request body and fill in $_POST. Try replacing your current error_page directive with:
location @redir {
rewrite ^ /index.php;
}
error_page 404 = @redir;
check these:
<form method="post">
you using the post method?
try running the profiler:
$this->output->enable_profiler(TRUE);
seeing any POST output there?
I was using my own PHP framework with similar URI rewrites as CI and on Nginx server had similar issues, cause my forms had actions like: action="admin/login/post" and I had to change them to end with .php action="admin/login/post.php" so they could work, but this requires you to change the URI rewrite of your CI class to replace that .php from the uri string.
I had a similar problem and i tried everything mentioned here. It was very simple when i figured it, I had not named my input variables in the form. I had missed the name parameter.
<input type="name" placeholder="Name" name="name">
精彩评论