?
Solved

PHP page failing to receive POSTed form data

Posted on 2011-03-15
13
Medium Priority
?
263 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
12 Comments
 
LVL 17

Expert Comment

by:psimation
ID: 35144298
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
ID: 35144342
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
ID: 35144419
Can you post your code?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 17

Assisted Solution

by:psimation
psimation earned 800 total points
ID: 35144632
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 1200 total points
ID: 35145001
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
ID: 35174053
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
 
LVL 35

Author Comment

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

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 1200 total points
ID: 35174678
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
ID: 35176772
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
ID: 39551279
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
ID: 39551280
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
ID: 39551282
I found my own solution, but comments from others helped me get there - thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

588 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