Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

PHP page failing to receive POSTed form data

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
Terry Woods
Asked:
Terry Woods
  • 6
  • 2
  • 2
  • +2
4 Solutions
 
psimationCommented:
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
 
Terry WoodsIT GuruAuthor Commented:
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
 
Jagadishwor DulalBraces MediaCommented:
Can you post your code?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
psimationCommented:
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
 
Lukasz ChmielewskiCommented:
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
 
Terry WoodsIT GuruAuthor Commented:
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
 
Terry WoodsIT GuruAuthor Commented:
ps: There was a typo in the code above - </form should read </form>
0
 
Lukasz ChmielewskiCommented:
Is the WebsiteA some kind of keyname ? Did you check for existence of that path in your php.ini ?
0
 
Terry WoodsIT GuruAuthor Commented:
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
 
GaryCommented:
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
 
Terry WoodsIT GuruAuthor Commented:
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
 
Terry WoodsIT GuruAuthor Commented:
I found my own solution, but comments from others helped me get there - thanks!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 6
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now