Solved

PHP page failing to receive POSTed form data

Posted on 2011-03-15
13
208 Views
Last Modified: 2013-10-06
I have a website where all of a sudden submitting a form via POST returns no data in $_POST

I can't understand why $_POST is empty, as even a phpinfo() shows the _SERVER["REQUEST_METHOD"] is POST

Providing code for this isn't trivial as there are several files of supporting functions etc being used, and I have been changing some code in those prior to the problem but I don't know why it would make a difference. I'm really hoping someone's seen this before, and can provide a quick fix!

Using Apache on Debian Linux (a fairly old version), PHP version is 5.2.9.
0
Comment
Question by:Terry Woods
  • 6
  • 2
  • 2
  • +2
13 Comments
 
LVL 17

Expert Comment

by:psimation
Comment Utility
Well, start with the basics.

1. Make sure the form still has "method="POST" " in it's attributes.
2. The values are stored in $_POST[], not $_POST.
0
 
LVL 35

Author Comment

by:Terry Woods
Comment Utility
Forms on more than one page that I haven't changed recently have stopped working too. I have been playing with code utilised by all pages affecting sessions, and have reviewed it but can't see anything that would seem to make a difference.

A print_r($_POST) run by the very first line of PHP code returns an empty array.
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
Comment Utility
Can you post your code?
0
 
LVL 17

Assisted Solution

by:psimation
psimation earned 200 total points
Comment Utility
Another quick test to ensure that it's not something "globally" broken is to just create a very quick 1 field form on the same domain and making sure that it still works.
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 300 total points
Comment Utility
Did you try different browsers ?
I'd go with psimation's suggestion, create one simple form and check it there, this way we can rule out the environmental cause. If it works - then it's your code.
0
 
LVL 35

Author Comment

by:Terry Woods
Comment Utility
Ok, after trying all sorts of simplifications, I've found the behaviour described below. Let's assume my website sits in a folder called web_root/WebsiteA, web_root being the Apache web root.
- putting a test script (below) in my website folder web_root/WebsiteA shows $_POST to be empty in IE7, but populated for FireFox
- putting the test script into any other folder (the parent folder of my website (web_root), or a sibling level [ie a different website] folder eg web_root/WebsiteB) shows $_POST to be populated when submitted
- changing the website's folder from "WebsiteA" to "WebsiteB" fixes the problem - submitting the form shows $_POST to be populated

Does this point towards there being a problem with Apache on that particular folder name?
<?
print "POST:<pre>";
print_r($_POST);
print "</pre>";
?>
<form method="POST" action="">
<input type="submit" value="Save Changes">
<input type="hidden" name="blah" value="1">
</form

Open in new window

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 35

Author Comment

by:Terry Woods
Comment Utility
ps: There was a typo in the code above - </form should read </form>
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 300 total points
Comment Utility
Is the WebsiteA some kind of keyname ? Did you check for existence of that path in your php.ini ?
0
 
LVL 35

Author Comment

by:Terry Woods
Comment Utility
The actual name is C1060 - it's not mentioned in the php.ini file, or any Apache conf files as far as I can see.
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
I've requested that this question be deleted for the following reason:

The question has either no comments or not enough useful information to be called an "answer".
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 0 total points
Comment Utility
Update - here are some more details, and the solution. Perhaps this will be useful to others!

This forum post appears to describe the issue: http://lists.rubyonrails.org/pipermail/rails/2006-March/027283.html

   You cannot post any data to mixed NTLM and non-NTLM authenticated Web sites. Microsoft Internet Explorer requires NTLM authentication for all visits to a website after you visit one NTLM authenticated folder of the website.
I can confirm this behaviour as follows:

When I visit http://mydomain/websiteA/index.php then http://mydomain/websiteA/POST_test.php $_POST is not populated by submitting the test page.

However, closing all my IE7 windows then browsing straight to http://mydomain/websiteA/POST_test.php shows $_POST IS populated by submitting the test page.

And one of the suggested solutions from the above linked forum post appears to be:

   
The only way I have seen to get IE to "forget" it has previously NTLM-authenticated to a site is to send a 401 page status. This effectively resets the IE authentication state.

It turned out that the problem was caused by a previous request to an unrelated page which made use of NTLM authentication like this (or similar):

<?php
  if (!isset($headers['Authorization'])){
    header('HTTP/1.1 401 Unauthorized');
    header('WWW-Authenticate: NTLM');
    exit;
  }
?>

Open in new window


After that authentication was done, all $_POST data was received empty until IE was closed and re-opened. I worked around the issue by removing the above code and instead arranging for Apache to use NTLM within our Intranet (which sets the $_SERVER['REMOTE_USER'] variable). (Outside of our intranet, Apache authentication is still used).
0
 
LVL 35

Author Closing Comment

by:Terry Woods
Comment Utility
I found my own solution, but comments from others helped me get there - thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery, html5 UI 1 47
Flexbox in CSS3 2 25
while loop in html mail format 5 32
How to display a functions data inside HEREDOC 2 13
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now