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

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,
LVL 2
mindgardenerAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
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
 
acbxyzCommented:
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
 
mindgardenerAuthor Commented:
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Kim WalkerWeb Programmer/TechnicianCommented:
I don't want to overlook the obvious. Is the form set to method="post"?
0
 
mindgardenerAuthor Commented:
yes...the method is 'post' in the form
0
 
acbxyzConnect With a Mentor Commented:
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
 
mindgardenerAuthor Commented:
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
 
Kim WalkerWeb Programmer/TechnicianCommented:
What version of PHP?
0
 
mindgardenerAuthor Commented:
5.3.6
0
 
Dave BaldwinFixer of ProblemsCommented:
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
 
designatedinitializerConnect With a Mentor Commented:
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
 
Dave BaldwinFixer of ProblemsCommented:
It's not XAMPP, the response header says Fedora which is a Linux distribution.  XAMPP response says Win32 and some other stuff.
0
 
Kim WalkerConnect With a Mentor Web Programmer/TechnicianCommented:
Do you have another server you can point your form at to verify it is sending a $_POST array?
0
 
rinfoConnect With a Mentor Commented:
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
 
mindgardenerAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.