I have an HTML form POSTing to the following index.php:
<?php require_once("/home/full/path/to/included/file.php"); ?>
And in file.php, I am trying to access $_POST:
ob_start();
session_start();
var_dump($_POST);
$contents = ob_get_contents();
ob_end_clean();
echo $contents;
But var_dump($_POST) returns an empty array.
Moving the ob functions to the index.php has no effect.
If I put the var_dump($_POST) before ob_start(), OR if I remove the output buffering altogether, the problem disappears, but I need output buffering. So in an effort to hunt down the problem, I tried POSTing the form data to a test.php:
ob_start();
$session_start;
var_dump($_POST);
$contents = ob_get_contents();
ob_end_clean();
echo $contents;
And it displayed everything fine. So the problem with my file.php seems to be that it is both included, and using output buffering. Do you see a problem with my setup? Why can't $_POST be accessed by an included, output-buffered script? Do you see a way to fix this, or an alternative? Thanks.
EDIT: One other possible factor: My HTML form tag is this:
<form action="/" method="POST">
I use mod_rewrite to redirect that to index.php. I try action="/index.php" and nothing changes, so it shouldn't matter.