[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2012-03-29
15
Medium Priority
?
3,014 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

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.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month19 days, 8 hours left to enroll

872 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