Solved

Post not working in php. print_r($_POST) giving empty array

Posted on 2012-03-29
15
2,586 Views
Last Modified: 2012-06-27
Hi -

I setup a new web server using php and I see that I am not able to access
post variables in the php script. When I do print_r($_POST), it gives me empty array.

Get variables works.

I enabled register_globals, and always_populate_raw_post_data in php.ini to On. The php post is not working after the change. Is there any other php.ini variable that is causing the issue ?

Let me know how I can check what is going wrong.

Thanks,
0
Comment
Question by:mindgardener
  • 5
  • 3
  • 2
  • +4
15 Comments
 
LVL 10

Expert Comment

by:acbxyz
ID: 37784688
Did you check $_POST without enabling those two options? Besides register_globals is deprecated and can be a big security hole.

I had problems with empty $_POST when some pages use ntlm-authentication and some files in the same directory do not. Without authentication no post-data was send.
0
 
LVL 2

Author Comment

by:mindgardener
ID: 37784703
Yes...So initially these two variables was set to Off. And for testing purpose I enabled it.

I am testing with firefox POSTER plugin to call the php file.  How can I check for ntlm-authentication ?
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 37784835
I don't want to overlook the obvious. Is the form set to method="post"?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
LVL 2

Author Comment

by:mindgardener
ID: 37784844
yes...the method is 'post' in the form
0
 
LVL 10

Assisted Solution

by:acbxyz
acbxyz earned 100 total points
ID: 37784857
If you didn't configure something with authentication, it is off. You would see an additional HTTP/401 response before the real page (HTTP/200) would be delivered to your browser.

You can use phpinfo(); on the destination page to show all given variables in the last section.
0
 
LVL 2

Author Comment

by:mindgardener
ID: 37784966
Here is the http response when I call the page

HTTP/1.1 200 OK
Date: Thu, 29 Mar 2012 22:34:11 GMT
Server: Apache/2.2.17 (Fedora)
X-Powered-By: PHP/5.3.6
Content-Length: 3838
Connection: close
Content-Type: text/html; charset=UTF-8
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 37784967
What version of PHP?
0
 
LVL 2

Author Comment

by:mindgardener
ID: 37784987
5.3.6
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37785136
I don't think any PHP variable is causing the problem.  Maybe because on 40 or 50 servers and maybe 20 different versions of PHP, I've never seen that happen.  I see the response but what did the request look like?  And what is the form code?
0
 
LVL 7

Assisted Solution

by:designatedinitializer
designatedinitializer earned 100 total points
ID: 37785499
Are you using XAMPP?
I got crazy, untreatable problems with it. (so I ditched XAMPP some time ago)

I would start by putting this on the very top of the page:

die(print_r($_REQUEST,2));

If this shows some values, then the problem is a silent error in that page.
If this doesn't show, then the problem is a silent error in the calling page.

You should also check the php error log.
It's amazing how many of these errors are simply typos.
(i have a few everyday =)
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37785509
It's not XAMPP, the response header says Fedora which is a Linux distribution.  XAMPP response says Win32 and some other stuff.
0
 
LVL 22

Assisted Solution

by:Kim Walker
Kim Walker earned 100 total points
ID: 37785522
Do you have another server you can point your form at to verify it is sending a $_POST array?
0
 
LVL 9

Assisted Solution

by:rinfo
rinfo earned 100 total points
ID: 37786488
Have you checked
POST_MAX_SIZE in php.ini.
May be it contains an inappropriate value.
If this contains say 20M instead of 20MB the value will be treated as zero  and POST will not
return any value in the array.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 100 total points
ID: 37793120
I enabled register_globals...
Here is an explanation of why you should not do that.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_7317-Register-Globals-a-bad-idea-from-day-one.html

PHP has an introductory tutorial about using HTML forms.  Please see:
http://php.net/manual/en/tutorial.forms.php

Please install this script and run it to see the moving parts.  Please post the output back here, thanks.  You can also test it on my server, here:
http://www.laprbass.com/RAY_post_example.php

<?php // RAY_post_example.php
error_reporting(E_ALL);
echo "<pre>"; // MAKE IT EASY TO READ



// THIS ILLUSTRATES THE RELATIONSHIP BETWEEN THE 'ACTION' AND THE 'FORM' WHEN COMBINED INTO A SINGLE PHP SCRIPT FILE



// SET A DEFAULT VALUES FOR A VARIABLE TO PREPOPULATE THE FORM - THIS COULD COME FROM A DATA BASE, OR MIGHT BE EMPTY
$my_input_Field = 'ORIGINAL DATA';



// HAS ANYTHING BEEN POSTED? IF SO, $_POST IS SET AND CONTAINS THE DATA
if (!empty($_POST))
{
    // THIS IS THE ACTION SCRIPT.  IN THIS EXAMPLE CODE, ALL WE DO IS SHOW THE POST ARRAY
    var_dump($_POST);

    // IF THE FORM WAS FILLED IN, COPY THE INPUT INTO OUR VARIABLE
    if (!empty($_POST["my_input_Field"]))
    {
        $my_input_Field = $_POST["my_input_Field"];
    }

    // THIS IS THE END OF THE ACTION SCRIPT
    echo 'ACTION COMPLETED';

    // THIS SHOWS HOW A NOTICE IS ISSUED FOR A NON-EXISTENT INPUT CONTROL
    $x = $_POST["my_input_Field"];
}



// THIS IS THE FORM SCRIPT CREATED IN HEREDOC NOTATION
$form = <<<ENDFORM
<form method="post">
TYPE SOMETHING HERE:
<input type="text"   name="my_input_Field"   value="$my_input_Field" />
<input type="hidden" name="my_HIDDEN_Field"  value="Not Really Much of a Secret" />
<input type="submit" name="my_SUBMIT_Button" value="go" />
</form>
ENDFORM;

// WRITE THE FORM TO THE BROWSER
echo $form;

Open in new window

0
 
LVL 2

Author Comment

by:mindgardener
ID: 38076001
I found out the issue. The issue was in my web server, inter post API calls were not working. Some server setting was causing this issue. By moving things to right port, we got it working.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

839 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