Solved

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

Posted on 2012-03-29
15
2,473 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 21

Expert Comment

by:Kim Walker
ID: 37784835
I don't want to overlook the obvious. Is the form set to method="post"?
0
 
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 21

Expert Comment

by:Kim Walker
ID: 37784967
What version of PHP?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 2

Author Comment

by:mindgardener
ID: 37784987
5.3.6
0
 
LVL 82

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 82

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 21

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 108

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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

16 Experts available now in Live!

Get 1:1 Help Now