?
Solved

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

Posted on 2012-03-29
15
Medium Priority
?
2,846 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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 400 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 84

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 400 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 84

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 400 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 400 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 111

Accepted Solution

by:
Ray Paseur earned 400 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

Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

Question has a verified solution.

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

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.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.
Suggested Courses

765 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